C program to print Floyd’s triangle

Logic: 

  1. Input how many (numbers of )rows of Floyd’s triangle to print.

      For example, First four rows of Floyd’s triangle are:                                              1   

                             2 3                                         
                             4 5 6        

2. In Floyd’s triangle, nth row contains n numbers.

				
					#include <stdio.h> 
#include<conio.h> 
void main() 
{
int n, i,  c, a = 1;
clrscr(); 
printf("Enter the number of rows of Floyd's triangle to print\n"); 
scanf("%d", &n);
for (i = 1; i <= n; i++) 
{  
for (c = 1; c <= i; c++)   
{ 
printf("%d ",a);  
a++; 
}
printf("\n");
} 
getch();
}
				
			

Leave a Reply