[c]Extension of previous triangle pattern with numbers

Get a mirror image of the pattern on previous post.
This exercise is the same as previous, just print the columns..

here’s the code:

#include <stdio.h>

int main()
{
    int num,rows,cols;
    printf("Enter the rows:");
    scanf("%d",&num);
    
    for(rows=1;rows<=num;rows++)
    {
        for(cols=1;cols=1;rows--)
    {
        for(cols=1;cols<=rows;cols++)
        {
               printf("%d",cols);
            
        }
        printf("\n");
    }
    
    return 0;
}

Looks like this when user enter 5:

Enter the rows:5
1
12
123
1234
12345
1234
123
12
1

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s