Reputation: 423
I am trying to create a program which prints 6 * 10 times using a for loop, but it does not work correctly.
#include <stdio.h>
int main()
{
int i, num1 = 60, num2;
num2 = 60 / 10;
for (i=0;i<10;i++) {
printf("%d* \n", num2);
}
}
This prints 6*
ten times, but I want to print 6 six 10 times like this
******
******
******
......
Upvotes: 1
Views: 281
Reputation: 25352
What you are doing is took a loop and print same int with a star.
If you need to print 2D
grid, you have to use nested loop.
Like this
int i, j, num1 = 60, num2;
num2 = 60 / 10;
for (i = 0; i < 10; i++) {
for (j = 0; j < num2; j++)
printf("*");
printf("\n");
}
Upvotes: 4