Skip to content
Home » C program to print full diamond of numbers

C program to print full diamond of numbers

Learn about C program to print full diamond of numbers in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to print full diamond of numbers

     1
    123
   12345
  1234567
 123456789
  1234567
   12345
    123
     1

Program:

#include<stdio.h> 
int main()
{
   int n, a;

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

   for(int i=1; i<=n; i++)
   {
     a = 1;

     for(int j=i; j <= n; j++)
     {
       printf(" ");
     }

     for(int k=1; k <= 2*i-1; k++)
     {
       printf("%d",a++);
     }

     printf("\n");
   }
 
   for(int i=n-1; i>=1; i--)
   {
     a=1;
     for(int j=n; j>=i; j--)
     {
       printf(" ");
     }

     for(int k=1; k<=2*i-1; k++)
     {
       printf("%d",a++);
     }
     printf("\n");
   }

   return 0;
}

Output:

Enter number of rows: 5
     1
    123
   12345
  1234567
 123456789
  1234567
   12345
    123
     1

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

Similar Codes :
C program to print full diamond of spaces and stars
C program to print full diamond of stars