C program for Floyd’s triangle Number pattern using nested for
- Home
- Floyd's triangle
- C program for Floyd’s triangle Number pattern using nested for
- On
- By
- 0 Comment
- Categories: Floyd's triangle, Number pattern
C program for Floyd’s triangle Number pattern using nested for
C program for Floyd’s triangle Number pattern using nested for
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 to print triangle pattern using number
Code to floyd’s triangle pattern 1
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
Code to floyd’s triangle pattern 2
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
Code to floyd’s triangle pattern 3
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
Code to floyd’s triangle pattern 4
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
Code to floyd’s triangle pattern 5
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
Code to floyd’s triangle pattern 6
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
Code to floyd’s triangle pattern7
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