output from nested while loop
Hi, I'm trying to get the following output from a nested while loop:
enter=5:
1
22
333
4444
55555
I can do this fine with a for loop but cannot get it right with a 'while', and i'm not surewhat i'm doing wrong. The code i've got below outputs:
1
22
33
44
55
66...
Can anybody make a suggestion?? Thankyou
#include <stdio.h>
main()
{
int rows;
int num=1;
int col=1;
printf("\nEnter a number between 1-9\n"); //get values
scanf("%d",&rows);
if (rows > 9||rows < 1)
{
printf("\nSorry. Invalid input.\n");
return; //terminate program
}
while (num<= rows){ //outer loop
printf("%d\n",num);
num++;
while (col<= rows) //inner loop
col++;
printf("%d",num);
}//end while loop
return 0;
}//end main