Advertisement
Guest User

Untitled

a guest
May 30th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // ConsoleApplication7.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "cstdlib"
  6. #include "iostream"
  7. #include "math.h"
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. cin.clear();
  13. cin.sync();
  14. float a, b, c, d, e, x;
  15. float najb;
  16. cout << "Podaj 5 liczb: ";
  17. cin >> a >> b >> c >> d >> e;
  18. cout << a<<endl << b<<endl << c<<endl << d<<endl << e<<endl;
  19. float s = 0;
  20.  
  21. s = (a + b + c + d + e) / 5;
  22. cout << "Srednia to:" << s << endl;
  23. {
  24. x = fabs(s - a);
  25. s = a;
  26. }
  27.  
  28. if (fabs(s - b) < x)
  29. {
  30. x = fabs(s - b);
  31. najb = b;
  32. }
  33.  
  34.  
  35.  
  36. if (fabs(s - c) < x)
  37. {
  38. x = fabs(s - c);
  39. najb = c;
  40. }
  41.  
  42.  
  43.  
  44. if (fabs(s - d) < x)
  45. {
  46. x = fabs(s - d);
  47. najb = d;
  48. }
  49.  
  50.  
  51. if (fabs(s - e) < x)
  52. {
  53. x = fabs(s - e);
  54. najb = e;
  55. }
  56.  
  57.  
  58.  
  59. cout << "Liczba najblizsza sredniej to : " << najb;
  60. system("PAUSE");
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement