reverse printing [closed]
I'm workin开发者_开发问答g on a looping program that prints a series of numbers. I wonder how i do the reverse of this such that the output would be like
123456789
12345678
1234567
123456
12345
1234
123
12
1
My program is
#include <stdio.h>
int main (void)
{
//Local Declarations
int limit;
//Statements
for (int lineCtrl = 1; lineCtrl <= 9; lineCtrl++)
{
for (int numCtrl = 1;
numCtrl <= lineCtrl;
numCtrl++)
printf("%1d", numCtrl);
printf("\n");
}
//to exit the program
int temp;
printf("Enter an integer and press Enter to exit the program: ");
scanf("%d", &temp);
return 0;
}
The only line changed is the first for loop initialization:
#include <stdio.h>
int main (void)
{
//Local Declarations
int limit;
//Statements
for (int lineCtrl = 9; lineCtrl >= 1; lineCtrl--)
{
for (int numCtrl = 1;
numCtrl <= lineCtrl;
numCtrl++)
printf("%1d", numCtrl);
printf("\n");
}
//to exit the program
int temp;
printf("Enter an integer and press Enter to exit the program: ");
scanf("%d", &temp);
return 0;
}
精彩评论