Thursday, February 12, 2015

C program to create diamond pattern in C

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,l,rng;
char c='*';
clrscr();
printf("enter the range");
scanf("%d",&rng);
for(i=rng;i>=0;i--)
{
printf("\n");
for(j=0;j<=i;j++)
printf("%c",c);
for(k=i;k<=2*rng-i;k++)
printf(" ");
for(l=0;l<=i;l++)
printf("%c",c);
}
for(i=0;i<=rng;i++)
{
printf("\n");
for(j=0;j<=i;j++)
printf("%c",c);
for(k=i;k<=2*rng-i;k++)
printf(" ");
for(l=0;l<=i;l++)
printf("%c",c);
}
getch();
}

output:

No comments:

Post a Comment