ad

Monday, March 10, 2025

C Program Print Inverted Pyramid and pattern

C Program Print Inverted Pyramid and pattern

C Program Print Inverted Pyramid and pattern

Example 


#include<stdio.h>
int main()
{

int i,j,row;
printf("enter number row");
scanf("%d",&row);
for(i=row;i>=1;i--)
{

for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch ();
}





C Program Print Inverted Pyramid and pattern

Explain Program

Step :1

Includes the standard input/output library for functions like printf() and scanf().

Step :2

     int main() {

 Start of the main function where the execution begins.

Step :3

int i, j, row;

Declares three integer variables:

i and j are loop counters.

Step :4

printf("enter number row");

printf("Enter number of rows: ");

integer input from the user and stores it in the variable row

Step :5

for(i=row; i>=1; i--)

for(i=row; i>=1; i--)

 outer loop that controls the number of rows.

  user-input number (row) and decreases by 1 each time until it reaches 1.

 Step :6

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

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

 inner loop which prints asterisks * in each row.

  prints i number of asterisks. 

Step :7

printf("*");

printf("*");

Prints one asterisk on the same line (no newline character).

 Step :8

printf("\n");

printf("\n");

After printing all the asterisks in one row, this moves the cursor to the next line.

  each row of asterisks is printed on a new line.

 Step :9

getch();

C Program Print Inverted Pyramid and pattern

 Program Output 

C Program Print Inverted Pyramid

Related Post :-

Website about us page html and css

No comments:

Post a Comment