Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is my code i need to do the space as the one in the picture #include <stdio

ID: 3815408 • Letter: T

Question

this is my code i need to do the space as the one in the picture

#include <stdio.h>
#include <math.h>
#define SIZE 500
void preprocess(int brightness[SIZE][SIZE], int n)
{
int i, j;
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
if (brightness[i][j] < 0)
{
double d = 0;
int count = 0;
// coordinate in above row
if (i - 1 >= 0)
{
d += brightness[i-1][j];
count++;
if (j -1 >= 0)
{
d+= brightness[i-1][j-1];
count++;
}
if (j + 1 < n)
{
d+= brightness[i-1][j+1];
count++;
}
}
// row just below
if (i + 1 < n)
{
d += brightness[i+1][j];
count++;
if (j - 1 >= 0)
{
d+= brightness[i+1][j-1];
count++;
}
if (j + 1 < n)
{
d+= brightness[i+1][j+1];
count++;
}
}
// coordinate just left
if (j - 1 >= 0)
{
d += brightness[i][j-1];
count++;
}
// coordinate just right
if (j + 1 < n)
{
d += brightness[i][j+1];
count++;
}
brightness[i][j] = (int)nearbyint(d/count);
}
}
}
}
int findBrightSpotInSmaller(int brightness[SIZE][SIZE], int i, int j, int *coord1, int *coord2)
{
int max = brightness[i][j];
*coord1 = i;
*coord2 = j;
int r, c;
for(r = i; r < i+5; r++)
{
for(c = j; c < j+5; c++)
{
if (brightness[r][c] == 0)
{
return -1;
}
if (brightness[r][c] > max)
{
max = brightness[r][c];
*coord1 = r;
*coord2 = c;
}
}
}
return max;
}
void findBrightSpots(int brightness[SIZE][SIZE], int n)
{
printf("Grid size: %dx%d ", n, n);
printf("Bright spots: ");

int i, j;
int reported[n][n];
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
reported[i][j] = 0;
}
}
for(i = 0; i <= n-5; i++)
{
for (j = 0; j <= n-5; j++)
{
int coord1, coord2;
int maxBright = findBrightSpotInSmaller(brightness, i, j, &coord1, &coord2);
if (maxBright != -1)
{
if(reported[coord1][coord2] != 1)
{
printf("[%d,%d] %d ", coord1, coord2, maxBright);
reported[coord1][coord2] = 1;
}

}
}
}
}
int inputBrightness(int brightness[SIZE][SIZE])
{
int n;
scanf("%d", &n);

int i, j;

for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
scanf("%d", &brightness[i][j]);
}
}
return n;
}
int main()
{
printf("Poject #6; name ");
int brightness[SIZE][SIZE];
int n = inputBrightness(brightness);
preprocess(brightness, n);
findBrightSpots(brightness, n);
return 0;
}

Poject #6; name
Grid size: 20x20
Bright spots:
[9,11] 14
[10,6] 8
[8,9] 10
[9,10] 13
[10,11] 13
[11,11] 10
[14,10] 9

i want it like the one in the picture below:

Terminal -tcsh 49x 17 liberty Cprogs/% gcc brightest.c liberty Cprogs a.out brightest4. dat Project #6; Dan Resler Grid size 20x20 Bright spots: 9,111 14 110, 6 8 8, 9 10 L 9, 101 13 110,111 13 [11,11] 10 114, 10] 9 liberty cprogs/96 I

Explanation / Answer

Basically you need to right allign the numbers.

This can be achieved by specifying %2d instead of %d

%nd stands for width that is to be used in formatting the integer.

e.g. %8d will take 8 spaces and allign numbers to the right.

%d will just print the number without leaving any space before the digit.

Hope this helps.

Good program, just a bit of change needed.