Home C Language Basic C Programs Floyd triangle

Floyd triangle

Write a C program to print Floyd Triangle.

#include<stdio.h>

int main()

{

   int i,j,sum=1,n;

   printf(“Enter no.of lines : ”);

   scanf(“%d”,&n);

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

   {

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

         printf(“%d “,sum++);//Here we using post increment on ‘sum’

      printf(“\n”);

   }

   return 0;

}

Output:

Enter no.of lines: 4

1

2              3

4              5              6

7              8              9              10