In this tutorial, we will discuss C program for Floyd’s triangle Number pattern using nested for
In C language, we will discuss about Floyd’s triangle Number pattern using nested for in C programming language.
In C language, we can display many shapes such as Floyd’s triangle ,pyramids, rectangles and squares etc…
In this post, we display floyd’s triangle number pattern using Nested for loop in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int num,i,j; printf("Enter number of rows"); scanf("%d",&num); for(i=1; i<=num; i++){ for(j=1; j<=i; j++){ printf("%d",j); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows 7 1 12 123 1234 12345 123456 1234567
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int num,i,j; printf("Enter number of rows\n"); scanf("%d", &num); for(i=1; i<=num; i++){ for(j=1; j<=i; j++){ printf("%d",i); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows 7 1 22 333 4444 55555 666666 7777777
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j; printf("Enter number of rows\n"); scanf("%d", &rows); for(i=rows; i>=1; i--){ for(j=1; j<=i; j++){ printf("%d",j); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows 7 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j; printf("Enter number of rows\n"); scanf("%d", &rows); for(i=rows; i>=1; i--){ for(j=1; j<=i; j++){ printf("%d",i); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows 7 7777777 666666 55555 4444 333 22 1
Program 5
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,num=1; printf("Enter number of rows :"); scanf("%d", &rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ printf("%d",num); ++num; } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows :7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Program 6
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j; printf("Enter number of rows :"); scanf("%d", &rows); for(i=1; i<=rows; i++){ for(j=rows; j>=1; j--){ if(j<=i) printf("%d",j);else printf(" "); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
1 21 321 4321 54321 654321 7654321
Program 7
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k=1,l=1; printf("Enter number of rows :"); scanf("%d", &rows); for(i=1; i<=rows; i++){ l=k; for(j=1; j<=i; j++){ printf("%d",l++); k=l--; for(j=1; j<i; j++){ printf("%d",--l);}} printf("\n"); printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
1 21 321 4321 54321 654321 7654321
Program 8
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k=1,l=1; printf("Enter number of rows :"); scanf("%d", &rows); for(i=1; i<=rows; i++){ l=k; for(j=1; j<=i; j++) printf("%d",l++); k=l--; for(j=1; j<i; j++) printf("%d",--l); printf("\n"); printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows :4
1 232 45654 78910987
Program 9
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k; printf("Enter number of rows :"); scanf("%d", &rows); k=1; for(i=1; i<=rows; i++){ for(j=rows; j>=1; j--){ if(j>i) printf(" ");else printf("%3d",k++); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Program 10
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k; printf("Enter number of rows :"); scanf("%d", &rows); k=1; for(i=1; i<=rows; i++){ for(j=rows; j>=i; j--){ printf("%3d",k++); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results:
Enter number of rows :5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Similar post
Similar post
Floyd’s triangle number pattern using for loop in C
Floyd’s triangle pattern using nested for loop in Java
Floyd’s triangle pattern using nested while loop in Java
Hollow pyramid triangle pattern in C++ language
Rhombus pattern in Java using for loop
Rhombus pattern in C using while loop
Rhombus pattern in C++ using do-while loop
Suggested for you
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…