Program of Floyd’s triangle in C.

Floyd’s triangle:  Floyd’s triangle is defined by filling the rows of the  triangle with consecutive numbers, starting with the number one in the top left corner.

 

Let’s write a program which prints The Floyd’s triangle .

 

Step 1: Let’s open the Turbo C and write the following code.

 

Code :

 

// Add preprocessor

#include<stdio.h>

#include<conio.h>

void main()

{
long int i,j,k=1,r;

 

// Clear screen

clrscr();

printf(“enter range: \n”);

scanf(“%li”,&r);

printf(“floyd’s triangle :\n “);

for(i=0;i<r;i++)

{

 

// Logic

for(j=0;j<i;j++,k++)

{

printf(“%3li \n “,k);

}

printf(“\n”);

}

getch();

}

 

 

Step 2: Save it and name it FLOYD’S.CPP .

 

 

Step 3: Now compile it by pressing ALT+F9 or click on compile to check errors in prgram and correct them .

 

 

Step 4: Now RUN the program and see output.

 

Output:

 

output floyd's

 

Happy Coding.

 

 

 

 

 

 

 

Tags: , ,