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

C program to print half diamond of numbers

Learn about C program to print half 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 half diamond of numbers

1
123
12345
1234567
123456789
1234567
12345
123
1

Program:

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

  printf("Enter number of rows: ");
  scanf("%d",&n);
  
  for(int i=1; i< 2*n; i++)
  {
    a=1;
    if(i < n) place=i;
    else place = abs(2*n-i);
    
    for(int j=1; j<=2*place-1; j++)
    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 half diamond of numbers
C program to print half diamond of numbers and stars