Home » C program to print Floyd Triangle

C program to print Floyd Triangle

Below is the C code to display Floyd triangle pattern.

Floyd Triangle:

1

2 3

4 5 6

and so on up to n

#include <stdio.h>
int main(){
    int p,n,i,j;
    p=1;
    printf("Enter number of rows:\n");
    scanf("%d",&n);
    printf("The pattern of Floyd Triangle:\n");
    for(i=0;i<n;++i){
        for (j=0;j<=i;++j){
            printf("%d ",p);
            p+=1;
        }
    printf("\n");
    }
    return 0;
}

Output:

Enter number of rows:
6
The pattern of Floyd Triangle:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21