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
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; }
Pattern 2
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; }
Pattern 3
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; }
Pattern 4
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; }
Pattern 5
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; }
Pattern 6
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; }
Pattern 7
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; }
Pattern 8
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; }
Pattern 9
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; }
Pattern 10
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; }
Pattern 11
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; }
Pattern 12
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; }
Pattern 13
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; }
Pattern 14
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; }
Pattern 15
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; }
Pattern 16
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; }
Pattern 17
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; }
Pattern 18
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; }
Pattern 19
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; }
Pattern 20
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; }
Pattern 21
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; }
Pattern 22
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; }
Pattern 23
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; }
Pattern 24
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; }
Pattern 25
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;
}
Note:
- All the programs are compiled and executed in Dev C++ code editor and save with .c extension.