The code is attached.
int main{
int i, n;
printf("This program prints a table of squares.\n");
printf("Enter number of entries in table: ");
scanf_s("%d", &n);
getchar();
for (i = 1; i <= n; i++) {
printf("%10d%10d\n", i, i * i);
if (i % 24 == 0) {
printf("Press Enter to continue...");
while (getchar() != '\n')
;
}
}
return 0;
}
The code is to pause after outputting 24 squares and continue after pressing the enter.
I'm curious about the use of getchar()
after the scanf_s("%d", &n)
. If I delete it, the second 24 squares will be printed automatically without pressing the enter. What is the reason behind it?