C Program To Print Floyd Triangle

There are number of ways to display and Floyd triangle display consecutive numbers in different row. In this example, you will write a program to print Floyd triangle.

Advertisements

Before you begin, learn the basics of C programming language. If you know the basics, skip and continue reading.

Advertisements

Problem Definition

The program ask for number of row to print. When the user input the number, a list of consecutive numbers are printed for each row. The number of elements for each row also grows.

Suppose the user input is 5 , then five rows of consecutive number are printed and each row has one more number than the previous. See the figure below.

Floyd Triangle
Floyd Triangle

Program Source Code

#include <stdio.h>
#include <stdlib.h>
int main()
{ 
    int n,i,c,a=1;
    printf("Enter the Number of Rows for Floyd Triangle:\n");
    scanf("%d",&n);
    printf("\n");
for(i=1;i<=n;i++)
{
    for(c=1;c<=i;c++)
    {
        printf("%d\t",a);
        a++;
    }
    printf("\n");
}
getch();
return 0;
system("PAUSE"); 
return 0;
}

Output

Enter the Number of Rows for Floyd Triangle:
5

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

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.