C Number Pattern Program

Developing a number pattern program in C is simple if you are familiar with loops. To display a number pattern program, at least two nested loops are required. The outer loop is used for rows, and the inner loop is used to display columns. Loops can be made using the while or for loop but writing programs using for loop is more straightforward than the while loop. Following is the list of programs:


Pattern 1

number-pattern-program1
Program
#include<stdio.h> int main() { int i, j, k, size = 5; for (i = 0; i < size; i++) { for (j = 1; j < size-i; j++) { printf(" "); } for (k = 0; k <= i; k++) { printf("%d", (k+1)); } printf("\n"); } return 0; }
number-pattern-program1

Pattern 2

number-pattern-program2
Program
#include<stdio.h> int main() { int i, j, size = 5; for (i = 0; i < size; i++) { for (j = 0; j <= i; j++) { printf("%d", (j+1)); } printf("\n"); } return 0; }
number-pattern-program2

Pattern 3

number-pattern-program3
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=i;j>=1;j--) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program3

Pattern 4

number-pattern-program4
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=i;j<=5;j++) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program4

Pattern 5

number-pattern-program5
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program5

Pattern 6

number-pattern-program6
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=5;j>=i;j--) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program6

Pattern 7

number-pattern-program7
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=i;j<=5;j++) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program7

Pattern 8

number-pattern-program8
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=i;j>=1;j--) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program8

Pattern 9

number-pattern-program9
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=5;j>=i;j--) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program9

Pattern 10

number-pattern-program10
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",i); } printf("\n"); } return 0; }
number-pattern-program10

Pattern 11

number-pattern-program11
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=5;j>=i;j--) { printf("%d",i); } printf("\n"); } return 0; }
number-pattern-program11

Pattern 12

number-pattern-program12
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { printf("%d",i); } printf("\n"); } return 0; }
number-pattern-program12

Pattern 13

number-pattern-program13
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=5;j>=i;j--) { printf("%d",i); } printf("\n"); } return 0; }
number-pattern-program13

Pattern 14

number-pattern-program14
Program
#include<stdio.h> int main() { int i,j; for(i=1;i<=5;i++) { for(j=5;j>=1;j--) { if(i==j) printf("%d",i); else printf("*"); } printf("\n"); } return 0; }
number-pattern-program14

Pattern 15

number-pattern-program15
Program
#include<stdio.h> int main() { int i,j,k=1; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("%d",k++); } printf("\n"); } return 0; }
number-pattern-program15

Pattern 16

number-pattern-program16
Program
#include<stdio.h> int main() { int i,j; for(i=5;i>=1;i--) { for(j=1;j<i;j++)
{
printf(" ");
}
for(j=5;j>=i;j--) { printf("%d",j); } printf("\n");
} return 0; }
number-pattern-program16

Pattern 17

number-pattern-program17
Program
#include<stdio.h> int main() { int i,j,k; for(i=1;i<=5;i++) { j=i; for(k=1;k<=i;k++) { printf("%d",j++); } printf("\n"); } return 0; }
number-pattern-program17

Pattern 18

number-pattern-program18
Program
#include<stdio.h> int main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { if(j==5 || j==1 || i==1 || i==5) printf("1"); else printf(" "); } printf("\n"); } return 0; }
number-pattern-program18

Pattern 19

number-pattern-program19
Program
#include<stdio.h> int main() { int i,j; for(i=1;i<=5;i++) { for(j=5;j>i;j--) { printf(" "); } for(j=1;j<=i;j++) { printf("%d ",j); } printf("\n"); } return 0; }
number-pattern-program19

Pattern 20

number-pattern-program20
Program
#include<stdio.h> int main() { int i, j, k; for(i=1;i<=5;i++)
{ for(j=i;j<5;j++) { printf(" "); } for(k=1;k<(i*2);k++) { printf("%d",k); } printf("\n"); } for(i=4;i>=1;i--) { for(j=5;j>i;j--) { printf(" "); } for(k=1;k<(i*2);k++) { printf("%d",k); } printf("\n"); } return 0; }
number-pattern-program20

Pattern 21

number-pattern-program21
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=7;i+=2) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } for(i=5;i>=1;i-=2) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program21

Pattern 22

number-pattern-program22
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { printf("%d",i); } printf("\n"); } return 0; }
number-pattern-program22

Pattern 23

number-pattern-program23
Program
#include<stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program23

Pattern 24

number-pattern-program24
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=5;j>=1;j--) { if(j>i) printf(" "); else printf("%d",j); } printf("\n"); } return 0; }
number-pattern-program24

Pattern 25

number-pattern-program25
Program
#include<stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=1;j<=5;j++) { if(j<i)
printf(" ");
else
printf("%d",j);
}
printf("\n");
}
return 0;
}
number-pattern-program25

Note:

  • All the programs are compiled and executed in Dev C++ code editor and save with .c extension.

More Topics