C Program to Print Inverted half Pyramid of Number
Example
C Program to Print Inverted half Pyramid of Number
Explain Program
Step :1
#include <stdio.h>
standard input/output library.
Step :2
void main()
main function where the program starts.
Step :3
Variable Declarations
int i, j, r;
r: The number of rows (user input).
i: Controls the outer loop (rows).
j: Controls the inner loop (columns/numbers per row).
Step :4
printf("enter the number");
scanf("%d", &r);
user to enter an integer value r
the number of rows in the pattern
Step :5
Outer Loop (Row Control)
for(i = r; i >= 1; i--)
Start from i = r and decrements down to 1.
Each iteration represent one row in the output.
number of values printed in a row equals i.
Step :6
for(j = 1; j <= i; j++)
{
printf("%d", j);
}
each row, this loop prints numbers starting from 1 up to i.
Step :7
printf("\n");
row move the cursor to the next line.
Step :8
return 0;
C Program to Print Inverted half Pyramid of Number
Program Output :-
Related Post :-
C Program Print Right Half Character Pyramid Pattern
C program print square star pattern
No comments:
Post a Comment