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

C program to print half diamond of numbers and stars

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

1
2*2
3*3*3
4*4*4*4
3*3*3
2*2
1

Program:

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

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

  for(int i=1; i< 2*n; i++)
  {
    if(i < n) place=i;
    else place = abs(2*n-i);

    for(int j=1; j< 2*place; j++)
    if(j%2==0) printf("*"); 
    else printf("%d",place); 

    printf("\n"); //next line
  }

  return 0;
}

Output:

Enter number of rows: 4
1
2*2
3*3*3
4*4*4*4
3*3*3
2*2
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 stars
C program to print half diamond of stars