ad

Tuesday, March 11, 2025

C Program print Inverted Right Half Pyramid Star Pattern

https://webdesigningtheory.blogspot.com/
C Program print Inverted Right Half Pyramid  Star Pattern

Example :- 

//inverted half pyramidoc c language


#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 Right Half Pyramid  Star Pattern

Explain Program

Step :1

#include<stdio.h>

  • Standard Input Output header file.
  • Functions like printf() and scanf() are defined in stdio.h.

Step :2

int main()

  • main function

Step :3

int i, j, row;

  • Declares three integer variables:
  • row: stores the number of rows of the triangle (user input).
  • i and j: loop control variables used in for loops.

Step :4

printf("enter number row");
  •  user to enter the number of rows.

Step :5

scanf("%d",&row);

  •  input, stores to  the variable row.
  • %d tells the compiler you're expecting an integer

Step :6

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

  • outer loop which run from row downs to 1.
  • It control the number of line (or rows) to print.

Step :7

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

  • This is the inner loop which prints the asterisks * in each row.
  • On each line, the number of asterisks equals the current value of i.

Step :8

printf("*");

  • Prints one asterisk without a newline.

Step :9

printf("\n");

  •  prints a newline to move to the next row.

getch();


C Program print Inverted Right Half Pyramid  Star Pattern

Program Output :-



Related Post :-


No comments:

Post a Comment