C Program to Display Floyd’s Triangle Pyramid Pattern
Example
#include<stdio.h>
int main()
{
int row,i,j,number=1;
clrscr();
printf("enter the number");
scanf("%D",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",number);
++number;
}
printf("\n");
}
getch();
return 0;
}
C Program to Display Floyd’s Triangle Pyramid Pattern
Explain Program
Step :1
#include <stdio.h>
- Standards Input/Output Library.
- using printf() and scanf().
Step :2
int main()
- entry point of the program.
Step :3
int row, i, j, number = 1;
- row :- User input for number of rows in Floyd's Triangle.
- i :- Loop variable for rows.
- j :- Loop variable for elements in each row.
- number :- Holds the current number to print; starts at 1.
Step :4
printf("Enter the number of row ");
- input how many rows they want in the triangle.
Step :5
scanf("%d", &row);
- user input and stores variable row.
- format specifier for integers.
Step :6
for(i = 1; i <= row;
i++)
- number of rows in the triangle.
- Runs from 1 to row
Step :7
for(j = 1; j <= i; j++)
- Control the number of element row.
- Each row i contains exactly i numbers.
Step :8
printf("%d ", number);
- Prints a space.
Step :9
printf("\n");
- next line after each row is printed
Step :10
return 0;
successful termination of the program
No comments:
Post a Comment