Saturday, February 14, 2009

CS 121 EXER5

Photobucket
#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; 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; 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;
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! ;)) getch(); }

No comments:

Post a Comment