diff --git a/C++/floyd_triangle.c b/C++/floyd_triangle.c new file mode 100644 index 00000000..b52dfa7d --- /dev/null +++ b/C++/floyd_triangle.c @@ -0,0 +1,21 @@ +#include +#include +void main() +{ + int num, i, j, k = 1; + + printf( " Enter a number to define the rows in Floyd's triangle: \n"); + scanf( "%d", &num); + // use nested for loop + // outer for loop define the rows and check rows condition + for (i = 1; i <= num; i++) + { + // inner loop check j should be less than equal to 1 and print the data. + for (j = 1; j <= i; j++) + { + printf(" %2d", k++); + } + printf( "\n"); + } + getch(); +}