Advertisement
frustration

DONE.среднее квад. геом. гарм. квадр(функция)

Feb 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. //нахождение среднего арифметического, геометрического, гармонического и квадратического с условием.(функция)
  2.  
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. float findAr(float a, float b, float c) {
  11.     float ar = (a + b + c) / 3;
  12.     return ar;
  13. }
  14. float findGeo(float a, float b, float c) {
  15.     float geo = pow(a*b*c, 1. / 3);
  16.     return geo;
  17. }
  18. float findGarm(float a, float b, float c) {
  19.     float garm = 3 / (1 / a + 1 / b + 1 / c);
  20.     return garm;
  21. }
  22. float findKvad(float a, float b, float c) {
  23.     float kvad = sqrt((a*a + b * b + c * c) / 3);
  24.     return kvad;
  25. }
  26.  
  27. void condition(float a, float b, float c, float ar, float geo){
  28.     ((a != b || b != c || a != c) && (ar > geo)) ? cout << " verno arifmeticheskoe > geometricheskogo" : cout << " neverno";
  29. }
  30.  
  31. void solutions(int a){
  32.     float x, y, z;
  33.     for (int i = 0; i < a; ++i){
  34.         cout <<"x=";
  35.         cin >> x;
  36.         cout <<  "y=";
  37.         cin >> y;
  38.         cout <<"z=";
  39.         cin >> z;
  40.         cout <<findAr(x, y, z) << endl;
  41.         cout << findGeo(x, y, z) << endl;
  42.         cout << findGarm(x, y, z) << endl;
  43.         cout << findKvad(x, y, z) << endl;
  44.         condition(x, y, z, findAr(x, y, z), findGeo(x, y, z));
  45.         cout << endl;
  46.     }
  47. }
  48.  
  49. int main() {
  50.     int k;
  51.     cout <<"enter repetitions- ";
  52.     cin >> k;
  53.     solutions(k);
  54.  
  55.     getch();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement