C program to print Diamond Pattern
Write a program in C programming language to print the diamond pattern as the output of the C program. Below is the code of the C program -
/* C program to print diamond as output*/
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,j,k;
printf("enter number of rows in odd number");
scanf("%d",&n);
for(i=0;i<=(n/2);i++)
{
for(j=0;j<(n/2)-i;j++)
{
printf(" ");
}
for(k=0;k<(2*i)+1;k++)
{
printf("*");
}
printf("\n");
}
for(i=0;i<n/2;i++)
{
for(j=0;j<i+1;j++)
{
printf(" ");
}
for(k=0;k<n-2-(2*i);k++)
{
printf("*");
}
printf("\n");
}
getch();
}
From the above code of the C program you will get the output as follows -
4 Comments
→

very good and simly method is used in program so we are all greatful to yuo…
Hey, It is not the exact logic for a given program.
Here i m giving the code with minimum number of executing steps.
also i m sure that there doesn’t exist any other way to print the same Diamond such that code executing steps will be less than mine.
It is not copied from any website, book etc.
#include
void main()
{
int n,i,s,k,flagReverce=0;
printf(“Enter the no. of rows\n”);
scanf(“%d”, &n);
for (i=1; i>=1; i++)
{
for (s=n; s>i; s–)
printf(” “);
for(k=1; k<(i*2)-1; k++)
printf("*")
printf("\n")
if (i == n)
flagReverce = 1
if (flagReverce = 1)
i-=2
}
}
It’s nice. Thank you.
Kiran is there any other easy code..