开发者

reverse printing [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜