Advertisement
savovaap_

Square_Rectangle_Triangle_Circle

Mar 29th, 2023
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. float areaOfSquare (int a) {
  6.     float result;
  7.     result=a*a;
  8.     return result;
  9. }
  10. float areaOfRectangle (int x,int y) {
  11.     float result1;
  12.     result1=x*y;
  13.     return result1;
  14. }
  15. float areaOfTriangle (int b,int c) {
  16.     float result2;
  17.     result2=b*c/2;
  18.     return result2;
  19. }
  20. float areaOfCircle (float radius) {
  21.     float result3;
  22.     result3=radius*radius*M_PI;
  23.     return result3;
  24. }
  25. int main () {
  26.     int number,a,x,y,b,c;
  27.     float radius,area;
  28.     printf("Enter number: ");
  29.     scanf("%d",&number);
  30.  
  31. if (number==1) {
  32.     printf("a= ");
  33.     scanf("%d",&a);
  34.     area=areaOfSquare (a);
  35.     printf("area:%.2f\n",area);
  36. }
  37. if (number==2) {
  38.     printf("x= ");
  39.     scanf("%d",&x);
  40.     printf("y= ");
  41.     scanf("%d",&y);
  42.     area=areaOfRectangle (x,y);
  43.     printf("area:%.2f\n",area);
  44. }
  45. if (number==3) {
  46.     printf("b= ");
  47.     scanf("%d",&b);
  48.     printf("c= ");
  49.     scanf("%d",&c);
  50.     area=areaOfTriangle (b,c);
  51.     printf("area:%.2f\n",area);
  52. }
  53. if (number==4) {
  54.     printf("radius= ");
  55.     scanf("%f",&radius);
  56.     area=areaOfCircle (radius);
  57.     printf("area:%.2f\n",area);
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement