Guest User

Untitled

a guest
Jan 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. int main()
  7. {
  8.     char choice=0;
  9.     double a, b, radius, area, perimeter, circumference;
  10.  
  11.     printf("Enter a 2D shape to compute area and perimeter: a - square, b - rectangle, c - circle\n");
  12.  
  13. switch (choice)
  14.    {
  15.        case 'a':
  16.         printf("Enter the side of the square:\n");
  17.         scanf("%lf", &a);
  18.             if(a <= 0) {
  19.                     printf("Invalid input.");
  20.                     return 0; }
  21.  
  22.        area=a*a;
  23.        perimeter=4*a;
  24.  
  25.        printf("Square area is:%f\n", area);
  26.        printf("Square perimeter is:%f\n", perimeter);
  27.        break;
  28.  
  29.         case 'b':
  30.                 printf("Enter the sides of the rectangle:\n");
  31.         scanf("%lf %lf", &a, &b);
  32.                 if((a <= 0) || (b <= 0)) {
  33.                     printf("Invalid input.");
  34.                     return 0; }
  35.  
  36.         area = a*b;
  37.         perimeter = 2*a + 2*b;
  38.  
  39.         printf("Rectangle area is:%f\n", area);
  40.         printf("Rectangle perimeter is:%f\n", perimeter);
  41.         break;
  42.  
  43.         case 'c':
  44.                 printf("Enter the radius of the circle:\n");
  45.         scanf("%lf", &radius);
  46.                 if(radius <= 0) {
  47.                     printf("Invalid input.");
  48.                     return 0; }
  49.  
  50.             area = M_PI*radius*radius;
  51.             circumference = 2*M_PI*radius;
  52.  
  53.             printf("Circle area is:%f\n", area);
  54.             printf("Circumference is:%f\n", circumference);
  55.             break;
  56.  
  57.         default:
  58.                 printf("Invalid input.");
  59.                 break;
  60.    }
  61.    }
  62.    return 0;
  63.  
  64. }
Add Comment
Please, Sign In to add comment