Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include "math.h"
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char* argv[])
  8. {
  9. const int nmax=20;
  10. float wektor[nmax];
  11. int a = 1, i;
  12. float n, suma=0, srednia=0, odchylenie=0, od=0;
  13. while (1)
  14. {
  15. cout << "Podaj wielkosc wektora n zawierajacego wyniki (<=" << nmax << ")" << endl;
  16. cin >> n;
  17. if (n > 0 && n <= nmax)
  18. {
  19. for (i = 0;i < n;i++)
  20. {
  21. cout << "Podaj wynik doswiadczenia [" << i + 1 << "]" << endl;
  22. cin >> wektor[i];
  23. suma += wektor[i];
  24. }
  25. cout << "Wektor ma postac:" << endl;
  26. for (i = 0; i < n; i++)
  27. cout << setw(8) << setprecision(2) << fixed << wektor[i] << " ";
  28. cout << endl;
  29. srednia = suma / n;
  30. cout << "Srednia arytmetyczna liczb w tym wektorze wynosi " << srednia << "" << endl;
  31. for (i = 0;i < n;i++)
  32. {
  33. od += (wektor[i] - srednia) * (wektor[i] - srednia) / n;
  34. }
  35. odchylenie = sqrt(od);
  36. cout << "Odchylenie standardowe wynosi "<<odchylenie <<""<< endl;
  37.  
  38. }
  39. else
  40. cout << "Zly rozmiar wektora." << endl;
  41. cout << "Aby ponownie odtworzyc program podaj dowolna liczbe calkowita, zas aby wyjsc z programu podaj 0." << endl;
  42. cin >> a;
  43. if (a == 0)
  44. break;
  45. return 0;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement