Advertisement
Sabab

Area

Jun 25th, 2018
1,789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main(){
  4.  
  5. int n,m;
  6. float lengthSq,lengthRect,breadthRect,radius,base,height,pi=3.1416;
  7. float area;
  8.  
  9. printf("Press 1 for proceeding and 2 for exiting the program....\n");
  10.  
  11. scanf("%d",&n);
  12.  
  13. if(n==1){
  14.  
  15.     printf("Ok, let's begin!!\n");
  16.     printf("Press 1 for measuring the area of a Square.\n");
  17.     printf("Press 2 for measuring the area of a Rectangle.\n");
  18.     printf("Press 3 for measuring the area of a Circle.\n");
  19.     printf("Press 4 for measuring the area of a Triangle.\n");
  20.  
  21.     scanf("%d",&m);
  22.  
  23.     if(m==1){
  24.         printf("Enter the length of the square: ");
  25.         scanf("%f",&lengthSq);
  26.         area=pow(lengthSq,2);
  27.         printf("Area: %f sq.unit\n",area);
  28.     }
  29.  
  30.     else if(m==2){
  31.  
  32.         printf("Enter the length of the rectangle: ");
  33.         scanf("%f",&lengthRect);
  34.         printf("Enter the breadth of the rectangle: ");
  35.         scanf("%f",&breadthRect);
  36.         area=lengthRect*breadthRect;
  37.         printf("Area: %f sq.unit\n",area);
  38.  
  39.  
  40.     }
  41.  
  42.     else if(m==3){
  43.         printf("Enter the raidus of the circle: ");
  44.         scanf("%f",&radius);
  45.         area=pi*radius*radius;
  46.         printf("Area: %f sq.unit\n",area);
  47.     }
  48.  
  49.     else if(m==4){
  50.  
  51.         printf("Enter the base of the triangle: ");
  52.         scanf("%f",&base);
  53.         printf("Enter the height of the triangle: ");
  54.         scanf("%f",&height);
  55.         area=(base*height)/2;
  56.         printf("Area: %f sq.unit\n",area);
  57.     }
  58.  
  59.     else{
  60.         printf("Invalid Input!!");
  61.     }
  62.  
  63.  
  64. }
  65.  
  66. else if(n==2){
  67.  
  68.     printf("bye!!");
  69. }
  70.  
  71. else{
  72.     printf("Invalid Input!!");
  73. }
  74.  
  75.  
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement