Pattern in C Programming

#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()
{
clrscr();
int a,b,n,c,d,x=0,y=1,l=1;
printf("Enter no. of lines:");
scanf("%d",&a);
clrscr();
b=a-1;
c=b;
d=a-2;
sachin:
n=a;
while(a>0)
{
x=x+3;
gotoxy(x,y);
delay(100);
textcolor(5);
cprintf("%2d",l);
l++;
a-- ;
}
a=n;
a-=2;
n=b;
while(b>0)
{
y=y+3;
gotoxy(x,y);
delay(100);
textcolor(5);
cprintf("%2d",l);
l++;
b-- ;
}
b=n;
b-=2;

n=c;
while(c>0)
{
x=x-3;
gotoxy(x,y);
delay(100);
textcolor(5);
cprintf("%2d",l);
l++;
c-- ;
}
c=n;
c-=2;
n=d;
while(d>0)
{
y=y-3;
gotoxy(x,y);
delay(100);
textcolor(5);
cprintf("%2d",l);
l++;
d-- ;
}
d=n;
d-=2;
if(a>0)
{
goto sachin;
}
getch();
}





No comments

Post your comments

Powered by Blogger.