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.
Step :6
for(j=1; j<=i; j++)
for(j=1; j<=i; j++)
inner loop which prints asterisks * in each row.
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.
No comments:
Post a Comment