I have been asked to write a program that creates the following pattern without simply printing this sequentially :
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
So far this is my code but it doesn't work. I am meant to use either a for loop or a while loop.
Code:
#include <stdio.h>
int main()
{
int i;
int max;
scanf("%d%c", &max);
while(max <= 10)
{
for(i = 1; i < max; i++)
{
printf("%d\n", i);
max--;
printf("%d\n", i);
}
}
return(0);
}
Can anyone help me?