C program to print inverted half left side of the pyramid number pattern

Ex: Write a C program to print inverted half left side of the pyramid number pattern. How to write a C program to print inverted half left side of the pyramid number pattern. C program to print inverted half left side of the pyramid number pattern.



Input from user:

Enter the number:

5


Expected output:

12345

  1234

    123

      12

        1



  Step by step logic of the given program:


1. Accept input number from user declare variable say no.


2. Run outer for loop from 1 to no which shows number of rows:

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


3. Run inner for loop from 1 to i-1 to print spaces: 

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

{

printf(" ");

}


4. Run another one inner for loop from 1 to (no+1)-i to print star:

for(k=1;k<=(no+1)-i;k++)

{

printf("%d",k);

}


5. For next row print \n.



  Program to print inverted half left side of the pyramid number pattern:


#include<stdio.h>

void main()

{

int i,j,k,no;

printf("Enter the number:\n");

scanf("%d",&no);

/*Run loops*/

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

{

     /* Print spaces from second row, in incremented manner*/

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

{

printf(" ");

}

     /* Print numbers in decremented manner*/

for(k=1;k<=(no+1)-i;k++)

{

printf("%d",k);

}


        /* For next row*/

printf("\n");

}


}



Above program shows the following output:


C program to print inverted half left side of the pyramid number pattern



No comments:

Post a Comment

If you have any doubts, please discuss here...👇