// Looping demo that draws asterisks on screen based on
// user number input.
// Starts off with a line of asterisks
// Eventually we'll draw a box of them
// Marc Chee marc.chee@unsw.edu.au
#include <stdio.h>
int main (void) {
int gridSize;
int exit = 0;
while(exit == 0) {
// take user input to set the grid size
printf("Please enter the size of the grid or 0 to exit: ");
scanf("%d", &gridSize);
if(gridSize == 0) {
exit = 1;
}
// print out the square grid
int y = 0;
while(y < gridSize) {
// print out one line
int x = 0;
while(x < gridSize) {
printf("*");
x = x + 1;
}
printf("\n");
y = y + 1;
}
}
return 0;
}
Resource created Wednesday 12 June 2019, 06:08:30 PM.
file: grid.c