Program 1- Menu-driven program to draw different shapes using the given in-built functions in C.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gd=DETECT,op,x,y,r,lux,luy,rex,rey,xs,ys,xe,ye,dd;
initgraph(&gd,&gm,"C:\\TC\\BGI");
do
{
printf("\n1.Circle");
printf("\n2.Line");
printf("\n3.Rectangle");
printf("\n4.Square");
printf("\n5.Exit");
printf("\nEnter your choice:");
scanf("%d",&op);
switch(op)
{
case 1:
printf("\nEnter the center and the radius of the circle((x,y) and (r)):");
scanf("%d%d%d",&x,&y,&r);
circle(x,y,r);
break;
case 2:
printf("\nEnter the start and end coordinates for line((xs,ys) and(xe,ye)):");
scanf("%d%d%d%d",&xs,&ys,&xe,&ye);
line(xs,ys,xe,ye);
break;
case 3:
printf("\nEnter the left upper and right bottom coordinates for rectangle((lux,luy) and(rex,rey)):");
scanf("%d%d%d%d",&lux,&luy,&rex,&rey);
rectangle(lux,luy,rex,rey);
break;
case 4:
printf("\nEnter the start coordinates and the length of the edge of a square(lux,luy,dd):");
scanf("%d%d%d",&lux,&luy,&dd);
rectangle(lux,luy,lux+dd,luy+dd);
break;
case 5:
exit(0);
default:
printf("\nInvalid choice");
break;
}
}while(op!=5);
getch();
closegraph();
}


No comments:

Post a Comment