C Program of Floyd's Triangle

Floyd's triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner:
1
23
456
78910
1112131415

C Program of Floyd's Triangle:


#include <stdio.h>

int main()
{
    int row, column, n;
    printf("Enter number of rows: ");
    scanf("%d",&n);
    int num = 1;
    for(row=1; row<=n ; row++){
        for(column=1; column<=row; column++){
            printf("%3d ",num);
            num++;
        }
        printf("\n");
    }
    return 0;
}

0 comments :

Post a Comment

Spam comments will be deleted. :)

 
Loading...
TOP