You are currently viewing Easy Diamond of Star printing solution in 2023

Easy Diamond of Star printing solution in 2023

Code for printing Diamond of Star

For learning c code, students are advised to practice few basic codes, Printing Diamond of Star is one of them.

In C code practice, this program logic plays a very important role. So I have designed this code as easy as possible for the students. They will be able to understand each and every step very easily. 

Before going for this type of program a student should go through basics of loop structure. So that they can easily go through each step with self explanation mode. 

For more code click here. For video tutorial on several topics click here

#include<stdio.h>

int main()
{
int h,i,j;

printf("Enter the height");
scanf("%d",&h);


for(i=1;i<=h;i++)
{
 for(j=1;j<40-i;j++)
  printf(" ");
 for(j=1;j<=i;j++)
  printf("* ");
 printf("\n");
}
for(i=h-1;i>=1;i--)//4, 3
{
 for(j=1;j<40-i;j++)//32
  printf(" ");
 for(j=1;j<=i;j++)//j=1..4 -----   1..3 ------  1..2 ---  1..1
  printf("* ");
 printf("\n");
}

}

Leave a Reply