Thursday, February 12, 2009

Exercise 5

Output

A-D


#include
#include
#include

void main(){
clrscr();
int h,i,j,x,y,choice,X;

printf("\nEnter your favorite number:");
scanf("%d",&h);
printf("\nSelect pattern you like to appear!");
printf("\n\t[A] for Pattern 1");
printf("\n\t[B] for Pattern 2");
printf("\n\t[C] for Pattern 3");
printf("\n\t[D] for Pattern 4");
printf("\nEnter your choice Pattern here:");
scanf("%s",&choice);
switch(choice)
{
case 'A':
for(i=1,y=10;i<=h;i++,y++) { for(j=1,x=35;j<=i;j++,x++) { gotoxy(x,y); printf("*"); } } break; } switch(choice) { case 'B': for(i=1,y=10;i<=h;i++,y++) { for(j=1,x=35;j<=i;j++,x--) { gotoxy(x,y); printf("*"); } } break; } switch(choice) { case 'C': for(i=h,y=10;i<=h;i--,y++) { for(j=i,x=35;j>=1;j--,x++)
{
gotoxy(x,y);
printf("*");
}
}
break;
}
switch(choice)
{
case 'D':
for(i=h,y=10;i>=1;i--,y++)
{
for(j=i,x=35;j>=1;j--,x--)
{
gotoxy(x,y);
printf("*");
}
}
break;
}
printf("\n\nYou got a nice pattern! ;)) \n\nby:\n\n ¯ L a d y");
getch();
}

No comments: