Posted By:
21 Jun, 2013 9:18 am PDT

Floyd Triangle in C

How can you print Floyd triangle?

We use two for loops to print the numbers as shown below :

     2    3  
   4 5     6  
7    8    9       10  

The number of lines is determined by the user.

The nth line in the triangle will contain n elements.

Please see the video for more details

Attachment: floydatriangle.c
Was it useful?  

For Floyed triangle , we use a nested loop . One to control the rows and other to control the numbers being printed.

Here is the code.


 int main()


 int n, i,  c, a =1;

 printf("Enter the number of rows of Floyd's triangle to print\n");


 for(i =1; i <= n; i++)   // controls the printing of rows.


    for(c =1; c <= i; c++)// controls the printing of numbers


      printf("%d ",a); // prints 1 in the first row.

      a++;               // 1 increases to 2 and so on..


    printf("\n");     // enters next line.




 To find detailed explanation of the program , have a look at the below attached file  to supplement your understanding of the video.

Was it useful?  

Please login to reply to this problem.