Print pattern in c - number pattern -4

number-pattern-4

Print pattern in c - number pattern -4


Write a program to print following pattern

54321
5432
543
54
5

Program code

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}


Step by Step solution

1. Number of row -

   Is has 5row  , so first loop will execute for 5 time
#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i<=5;i++)

    
{......
 }



    return 0;

}


2. Number of character -

 It has only one type of character , so there will be only one nested loop
#include <stdio.h>
int main()

{

......
 
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
 return 0;

}


3.Number of column -

It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row
#include <stdio.h>

............
      
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
...................


    return 0;

}


You can Browse related article below for more information and program code related to recursive function call

 Does above is helpful , Post you views in comment

DO NOT MISS OTHER C PROGRAMMING TUTORIAL

* indicates required






Comments

Popular posts from this blog

Copy Constructor

Print pattern in c - explore new perspectives in pattern printing

C program to check if the supplied year is leap year or not.