Skip to content
Home » C Program For Floyd’s Triangle

C Program For Floyd’s Triangle

Learn about C Program For Floyd’s Triangle in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program For Floyd’s Triangle

Floyd’s triangle is a right-angled triangular array of natural integers that is used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with successive integers beginning with a 1 in the top left corner.

example:

1    
2    3    
4    5    6    
7    8    9    10   
11   12   13   14   15

Program:

#include<stdio.h>
int main()
{
   int n, i, j, a=1;
   printf("Enter the number of rows: ");
   scanf("%d",&n);
   for(i=1; i<=n; i++)
   {
     for(j=1; j<=i; j++)
     printf("%-5d",a++);
     printf("\n");
   }
   return 0;
}

Output:

Enter the number of rows: 6
1    
2    3    
4    5    6    
7    8    9    10   
11   12   13   14   15   
16   17   18   19   20   21

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Program for Printing Pattern using Loops in C
Binary to Octal using Function