C Program To Print inverted Pyramid star pattern

Ex: Write a C Program To Print inverted Pyramid star pattern. How to write a C Program To Print inverted Pyramid star pattern. C Program To Print inverted Pyramid star pattern.


Input from user:
Enter the number:
7

Expected output:
*******
 ******
  *****
   ****
    ***
     **
      *
       



   Step by step logic of the given program:

1. Accept input(number) from user which shows number of rows, declare variable say no.

2. Run one outer  loop from 1 to no:
  for(i=1;i<=no;i++)

3. To print spaces run another for loop from 1 to i-1:
for(j=1;j<i;j++)
  printf(" ");
    

4. To print star use another one inner for loop from i to no:
for(k=i;k<=no;k++)
   printf(" *");
    

5. For new row, move to next line using \n.





   Program to print inverted pyramid star pattern:

#include<stdio.h>
void main()
{
int no,i,j,k;

printf("Enter the no\n");
scanf("%d",&no);

for(i=1;i<=no;i++)
{
for(j=1;j<i;j++)
printf(" ");

for(k=i;k<=no;k++)
printf(" *");

printf("\n");
}

}


Above program shows the following output:


C Program to print inverted pyramid star pattern



No comments:

Post a Comment

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