Solution for Exercise 10-14
ex1014
#include <stdio.h>
#define GRID 5
/* prototypes */
void forward(void);
void backwards(void);
int main()
{
puts("Grid forward:");
forward();
puts("Grid backwards:");
backwards();
return(0);
}
void forward(void)
{
int x,y;
for(x=0;x<GRID;x++)
{
for(y=0;y<GRID;y++)
printf("%d:%d\t",x,y);
putchar('\n');
}
}
void backwards(void)
{
int x,y;
for(x=GRID-1;x>=0;x--)
{
for(y=GRID-1;y>=0;y--)
printf("%d:%d\t",x,y);
putchar('\n');
}
}
Output
Grid forward:
0:0 0:1 0:2 0:3 0:4
1:0 1:1 1:2 1:3 1:4
2:0 2:1 2:2 2:3 2:4
3:0 3:1 3:2 3:3 3:4
4:0 4:1 4:2 4:3 4:4
Grid backwards:
4:4 4:3 4:2 4:1 4:0
3:4 3:3 3:2 3:1 3:0
2:4 2:3 2:2 2:1 2:0
1:4 1:3 1:2 1:1 1:0
0:4 0:3 0:2 0:1 0:0
Notes
* Only one change is required for this Exercise, at Line 3 to change the value assigned to GRID
.
Copyright © 1997-2024 by QPBC.
All rights reserved