What is Floyd's triangle?
From Wikipedia,
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 | ||||
2 | 3 | |||
4 | 5 | 6 | ||
7 | 8 | 9 | 10 | |
11 | 12 | 13 | 14 | 15 |
Problem of Floyd's Triangle:
Write a program in c language to print the floyd's triangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Solution/ C code of Floyd's triangle Now:
#include <stdio.h> int main() { int rows, i, j, number= 1; printf("Enter number of rows: "); scanf("%d",&rows); for(i=1; i <= rows; i++) { for(j=1; j <= i; ++j) { printf("%d ", number); ++number; } printf("\n"); } return 0; }
An output of that code in command and code in Code blocks Editor:
Tags:
C Program to Print Floyd's Triangle, Floyd's Triangle, Floyd's Triangle C Code, C code of Floyd's Triangle, Write the C code if Floyd's Triangle
No comments:
Post a Comment