C Program to Display Floyd’s Triangle Pyramid Pattern

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;

Declares variables:-
  • 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

C Program To Print Floyd's Triangle Pyramids  Pattern

 Program Output :- 

c program print floyd program


Related Post :-

c program to print full pyramid star

c program to print pascals triangle

c program to print inverted half

Comments

Popular posts from this blog

how to add background image in html.

HTML pre tag

How to insert image in html

Html anchor tag

Inline css in html