Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: Lei Hong Wei Class: P1H1 Date: 2 Dec 2016
- This program displays the menu for user to imput a choice.
- */
- #include <stdio.h>
- #include <math.h>
- void main(void)
- {
- char C;
- int x1, x2, y1, y2;
- float gradient, dist;
- printf("Menu\n");
- printf("0. Exit\n");
- printf("1. Calculate the distance between 2 points\n");
- printf("2. Calculate the slope of 2 points\n");
- printf("\nEnter your choice: ");
- scanf("%c", &C);
- if(C=='0')
- {
- printf("\nBye-bye\n");
- }
- else if(C=='1')
- {
- printf("\nEnter the first point (x1, y1): ");
- scanf("%d %d", &x1, &y1);
- printf("Enter the second point (x2, y2): ");
- scanf("%d %d", &x2, &y2);
- dist = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
- printf("\nDistance between the two points is %.2f.\n", dist);
- }
- else if(C=='2')
- {
- printf("\nEnter the first point (x1, y1): ");
- scanf("%d %d", &x1, &y1);
- printf("Enter the second point (x2, y2): ");
- scanf("%d %d", &x2, &y2);
- printf("\nThe slope is infinity because x1=x2.\n");
- }
- else
- {
- printf("\nInvalid choice!\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement