Skip to content
Home » Numbers Pattern Program in C

Numbers Pattern Program in C

Learn about Numbers Pattern Program in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Numbers Pattern Program in C

Pattern:

    1
    3    2
    4    5    6
   10    9    8    7
   11   12   13   14   15

Program:

#include<stdio.h>
int main()
{
   int n, r, c;
   int a=1, b;

   printf("Enter number of rows: ");
   scanf("%d",&n);

   for(r=1; r<=n; r++)
   {
     b=a+r-1;
     for(c=1; c<=r; c++, a++)
     {
       if(r%2==1) printf("%5d",a);
       else printf("%5d",b--);
     }

     printf("\n");
   }

   return 0;
}

Output:

Enter number of rows: 5
    1
    3    2
    4    5    6
   10    9    8    7
   11   12   13   14   15

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Pattern Programs in C for Floyd’s Triangle
Half Pyramid using Numbers in C