C program to print Floyds Triangle

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
 int i,j,n,a=1;

//Accepting limit
 printf("Enter the limit of triangle \n");
 scanf("%d",&n);

//Floyd's Triangle logic
 for(i=1;i<=n;i++)
 {
  for(j=1;j<=i;j++)
  {
   printf("%d\t",a);
   a++;
  }
  printf("\n");
 }
}

OUTPUT:

Enter the limit of triangle
5

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

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.