Denis_Hristov

PointerExe1

Mar 15th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. float squareS(int* a){
  6.     return (*a) * (*a);
  7. }
  8.  
  9. float rectS(int* a, int* b){
  10.     return (*a) * (*b);
  11. }
  12.  
  13. float triangleS(int* a, int* h){
  14.     return ((*a) * (*h)) /2;
  15. }
  16.  
  17. float circleS(int* r){
  18.     return M_PI * (*r) * (*r);
  19. }
  20.  
  21. int main()
  22. {
  23.     printf("Input number of the figure you want: \n1. Square\n2. Rectangle\n3. Rectangular triangle\n4. Circle\n");
  24.     int num;
  25.  
  26.     scanf("%d", &num);
  27.  
  28.     int a;
  29.     int b;
  30.     int h;
  31.     int r;
  32.     float s;
  33.  
  34.     if(num == 1){
  35.         printf("Input side of the square:\n");
  36.         scanf("%d", &a);
  37.  
  38.         s = squareS(&a);
  39.         printf("%.2f", s);
  40.     }else if(num == 2){
  41.         printf("Input sides of the rectangle:\n");
  42.         scanf("%d %d", &a, &b);
  43.  
  44.         s = rectS(&a, &b);
  45.         printf("%.2f", s);
  46.     }else if(num == 3){
  47.         printf("Input side and height of the triangle:\n");
  48.         scanf("%d %d", &a, &h);
  49.  
  50.         s = triangleS(&a, &h);
  51.         printf("%.2f", s);
  52.     }else if(num == 4){
  53.         printf("Input radius of the circle:\n");
  54.         scanf("%d", &r);
  55.  
  56.         s = circleS(&r);
  57.         printf("%.2f", s);
  58.     }else{
  59.         printf("Wrong number!");
  60.     }
  61.     return 0;
  62. }
  63.  
Add Comment
Please, Sign In to add comment