Q. Accept x and y coordinates of two points and write a menu driven program to perform the following operations till the user selects Exit.
i. Distance between points.
ii. Slope of line between the points.
iii. Check whether they lie in the same quadrant.
iv. EXIT
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double x1,y1,x2,y2,ans;
int ch;
printf("\nEnter Point A:");
scanf("%lf%lf",&x1,&y1);
printf("\nEnter Point B:");
scanf("%lf%lf",&x2,&y2);
printf("\n1.Distance\n2.Slop\n3.Quadrant\n4.Exit");
while(ch!=4)
{
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
ans=sqrt(ans);
printf("\nDistance is %lf:",ans);
break;
case 2:ans=(y2-y1)/(x2-x1);
printf("\nSlop is %lf:",ans);
break;
case 3:if(x1>0 &&x2>0 &&y1>0 &&y2>0)
printf("\nIn same quadrant and in First quadrant:");
break;
}
}
}
Output:
Enter Point A:3
5
Enter Point B:2
3
1.Distance
2.Slop
3.Quadrant
4.Exit
Enter your choice:2
Slop is 2.000000:
i. Distance between points.
ii. Slope of line between the points.
iii. Check whether they lie in the same quadrant.
iv. EXIT
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double x1,y1,x2,y2,ans;
int ch;
printf("\nEnter Point A:");
scanf("%lf%lf",&x1,&y1);
printf("\nEnter Point B:");
scanf("%lf%lf",&x2,&y2);
printf("\n1.Distance\n2.Slop\n3.Quadrant\n4.Exit");
while(ch!=4)
{
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
ans=sqrt(ans);
printf("\nDistance is %lf:",ans);
break;
case 2:ans=(y2-y1)/(x2-x1);
printf("\nSlop is %lf:",ans);
break;
case 3:if(x1>0 &&x2>0 &&y1>0 &&y2>0)
printf("\nIn same quadrant and in First quadrant:");
break;
}
}
}
Output:
Enter Point A:3
5
Enter Point B:2
3
1.Distance
2.Slop
3.Quadrant
4.Exit
Enter your choice:2
Slop is 2.000000:
0 Comments