EmbLogic's Blog

Write a program to print Diamond Pattern?

CODE:

#include<stdio.h>
int main()
{
int i,j,k,n,space,temp;
printf(“enter value of n\n”);
scanf(“%d”,&n);
temp=n;
for(i=1;i<=n;i++)
{
for(j=i;j<n;j++)
{
printf(” “);
}
for(k=1;k<(2*i);k++)
{
printf(“*”);
}
printf(“\n”);
}
temp=1;
for(i=n-1;i>=1;i–)
{
for(j=1;j<=temp;j++)
{
printf(” “);
}
temp++;
for(k=1;k<(i*2);k++)
{
printf(“*”);
}
printf(“\n”);
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>