Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. void choise();
  10. void distance();
  11. void hypotenus();
  12. void perimeter();
  13. void area_recetangle();
  14. void area_square();
  15.  
  16.  
  17. int main(void)
  18. {
  19. int user_choise = 1;
  20.  
  21.  
  22.  
  23. while(user_choise>0 && user_choise<=6)
  24. {
  25. choise() ;
  26. scanf("%d", &user_choise);
  27. switch(user_choise)
  28. {
  29. case 1:
  30. distance();
  31. break;
  32.  
  33. case 2:
  34. hypotenus();
  35. break;
  36.  
  37. case 3:
  38. perimeter();
  39. break;
  40.  
  41. case 4:
  42. area_recetangle();
  43. break;
  44.  
  45. case 5:
  46. area_square();
  47. break;
  48.  
  49. case 6:
  50. printf("goodbye");
  51. return (0);
  52. break;
  53.  
  54. default:
  55. break;
  56.  
  57.  
  58.  
  59.  
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. return (0);
  83. }
  84. /*
  85. this function calculates the choise
  86. */
  87. void choise()
  88. {
  89. printf("welcome to my calculator\n enter an option:\n1 - calc distance between 2 points\n2 - calc hypotenus triangle\n3 - calc area perimeter of circle\n4 - calc area of rectangle\n5 - area of square\n6 - exit");
  90.  
  91. }
  92.  
  93. /*
  94. this function calculates distance
  95. */
  96. void distance()
  97. {
  98. int x1 = 0;
  99. int x2 = 0;
  100. int y1 = 0;
  101. int y2 = 0;
  102.  
  103.  
  104. printf("pls enter the first two numbers\n");
  105. scanf("%d%d" , &x1 , &y1);
  106. getchar();
  107. printf("pls enter the second two numbers\n");
  108. scanf("%d%d" , &x2 , &y2);
  109. getchar();
  110.  
  111. int defferencex = x2 - x1;
  112. int differencey = y2 - y1;
  113.  
  114. double result = ((sqrt(pow(defferencex,2) + pow(differencey,2))));
  115. printf("distance is %lf\n" , result);
  116.  
  117.  
  118.  
  119.  
  120.  
  121. }
  122.  
  123. void hypotenus()
  124. {
  125. double x1 = 0;
  126. double x2 = 0;
  127.  
  128. printf("pls enter the first two numbers\n");
  129. scanf("%lf%lf" , &x1 , &x2);
  130. double hypotenus = (sqrt(pow(x1,2) + pow(x2,2)));
  131. printf("%lf" , hypotenus);
  132.  
  133.  
  134.  
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. void perimeter()
  144. {
  145. double radius = 0;
  146. printf("enter a radius");
  147. scanf("%lf" , &radius);
  148. double perimeter = radius*(2 * 3.14);
  149. double area = 3.14 * pow(radius,2);
  150. printf("%lf %lf" , perimeter , area);
  151.  
  152.  
  153.  
  154.  
  155. }
  156. void area_recetangle()
  157. {
  158. int width = 0;
  159. int length = 0;
  160. printf("enter the length\n");
  161. scanf("%d" , &length);
  162. printf("enter the width\n");
  163. scanf("%d" , &width);
  164. int area = length * width;
  165. printf("the area is: %lf\n" , area);
  166.  
  167.  
  168.  
  169.  
  170.  
  171. }
  172. void area_square()
  173. {
  174.  
  175. int width = 0;
  176. int length = 0;
  177. printf("enter the length\n");
  178. scanf("%d" , &length);
  179. printf("enter the width\n");
  180. scanf("%d" , &width);
  181. int area = length * width;
  182. printf("the area is: %lf\n" , area);
  183.  
  184.  
  185.  
  186.  
  187.  
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement