C program to print inverted half right side of pyramid star pattern

 Ex: Write a C program to print inverted half right side of pyramid star pattern. How to write a C program to print inverted half right side of pyramid star pattern. C program to print inverted half right side of pyramid star pattern.


Input from user:

Enter the number:

5


Expected output:

*****

****

***

**

*



  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 rows in pattern:

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


3. Run inner for loop from i to no which shows columns in pattern:

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


4. Inside the inner loop print star:

printf("*");


5. For next row print \n.





Program:


#include<stdio.h>

void main()

{

int i,j,no;

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

scanf("%d",&no);

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

{

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

{

printf("*");

}

printf("\n");

}

}



Above program shows the following output:


C program to print inverted half right side of pyramid star pattern



No comments:

Post a Comment

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