Half diomand shape
Write a program which takes a as input and draw the half diomand shape.
#include
#include
void main(void)
{
clrscr();
int a,b,n,i,j,sp1,sp2;
printf("Enter Odd Number = ");
scanf("%d",&n);
for(a=1;a<=n+2;a=a+2)
{
for(sp1=a;sp1<=n;sp1=sp1+2)
printf(" ");
for(b=1;b<=a;b++)
{
printf("%d",b);
}
printf("\n");
}
for(i=n;i>=1;i=i-2)
{
for(sp2=n;sp2>=i;sp2=sp2-2)
printf(" ");
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
#include
#include
void main(void)
{
clrscr();
int a,b,n,i,j,sp1,sp2;
printf("Enter Odd Number = ");
scanf("%d",&n);
for(a=1;a<=n+2;a=a+2)
{
for(sp1=a;sp1<=n;sp1=sp1+2)
printf(" ");
for(b=1;b<=a;b++)
{
printf("%d",b);
}
printf("\n");
}
for(i=n;i>=1;i=i-2)
{
for(sp2=n;sp2>=i;sp2=sp2-2)
printf(" ");
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
Comments
Post a Comment