Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. /* Name: Lei Hong Wei Class: P1H1 Date: 2 Dec 2016
  2. This program displays the menu for user to imput a choice.
  3. */
  4. #include <stdio.h>
  5. #include <math.h>
  6. void main(void)
  7. {
  8. char C;
  9. int x1, x2, y1, y2;
  10. float gradient, dist;
  11.  
  12. printf("Menu\n");
  13. printf("0. Exit\n");
  14. printf("1. Calculate the distance between 2 points\n");
  15. printf("2. Calculate the slope of 2 points\n");
  16. printf("\nEnter your choice: ");
  17. scanf("%c", &C);
  18.  
  19. if(C=='0')
  20. {
  21. printf("\nBye-bye\n");
  22. }
  23. else if(C=='1')
  24. {
  25. printf("\nEnter the first point (x1, y1): ");
  26. scanf("%d %d", &x1, &y1);
  27. printf("Enter the second point (x2, y2): ");
  28. scanf("%d %d", &x2, &y2);
  29.  
  30. dist = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
  31.  
  32. printf("\nDistance between the two points is %.2f.\n", dist);
  33. }
  34. else if(C=='2')
  35. {
  36. printf("\nEnter the first point (x1, y1): ");
  37. scanf("%d %d", &x1, &y1);
  38. printf("Enter the second point (x2, y2): ");
  39. scanf("%d %d", &x2, &y2);
  40.  
  41. printf("\nThe slope is infinity because x1=x2.\n");
  42. }
  43. else
  44. {
  45. printf("\nInvalid choice!\n");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement