Social Icons

Friday, 21 March 2014

C program to print Floyd's triangle

This program prints Floyd's triangle. Number of rows of Floyd's triangle is print and rows entered by the user. First four rows of Floyd's triangle are as follows :-
1
2 3
4 5 6
7 8 9 10
It's clear that in Floyd's triangle nth row contains n numbers.


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


                                               OUTPUT

No comments:

Post a Comment