Vladislav_Bezruk

CIRCLE AREA

Jul 9th, 2022
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. // ### task CIRCLE AREA ###
  2.  
  3. /* ### Description ###
  4.  
  5. There is a length of a circle. Find the area of the circle.
  6.  
  7. Input:
  8. A positive real number, the length of the circle.
  9.  
  10. Output:
  11. A real number, the area of the circle.
  12.  
  13. */
  14.  
  15. #include <iostream>
  16.  
  17. #include <iomanip>
  18.  
  19. #define _USE_MATH_DEFINES
  20. #include <cmath>
  21.  
  22. #ifndef M_PI
  23.     #define M_PI 3.14159265358979323846
  24. #endif
  25.  
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30.     //lenght of circle
  31.     double l;
  32.    
  33.     //reading length
  34.     cin >> l;
  35.    
  36.     //area of circle
  37.     double s;
  38.    
  39.     /*
  40.         know:
  41.             l = 2 * pi * r;
  42.            
  43.             s = pi * r^2;
  44.        
  45.         l^2 = 4 * pi^2 * r^2;
  46.        
  47.         l^2 / (4 * pi) = pi * r^2;
  48.        
  49.         l^2 / (4 * pi) = s;
  50.        
  51.         so:
  52.             s = l^2 / (4 * pi);
  53.     */
  54.    
  55.     //calculate the area
  56.     s = pow(l, 2) / (4 * M_PI);
  57.    
  58.     //printing area of circle
  59.     cout << fixed << setprecision(9) << s;
  60.    
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment