Advertisement
Guest User

Zad1

a guest
Mar 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1.  Zadanie domode wektor A(n).cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main()
  12. {
  13.     float suma = 0;
  14.     float srednia = 0;
  15.     int ilosc,i;
  16.     float suma1, srednia1,odchylenie;
  17.     suma1 = 0;
  18.     srednia1 = 0;
  19.     odchylenie = 0;
  20.     i = 0;
  21.     cout << "podaj ilosc elementow" << endl;
  22.     cin >> ilosc;
  23.     float*wektor = new float[ilosc];
  24.  
  25.     /*cout << "podaj pierwszy element" << endl;  
  26.     cin >> wektor[0];
  27.     cout << "podaj 4 element" << endl;
  28.     cin >> wektor[3];
  29.     cout << "pierwszy element wektora to  " << wektor[0] << endl;
  30.     cout << "4 element wektora to " << wektor[3] << endl;*/
  31.  
  32.     do
  33.     {
  34.         cout << "podaj " << i + 1 << " element wektora" << endl;
  35.         cin >> wektor[i];
  36.             suma = suma + wektor[i];
  37.             i++;
  38.  
  39.     } while (i + 1 <= ilosc);
  40.  
  41.             srednia = suma / ilosc;
  42.  
  43.             cout << "srednia wektora to: " << srednia << endl;
  44.            
  45.             int a = 0;  //obliczanie odchylenia standardowego
  46.  
  47.             do
  48.             {
  49.                 suma1=suma1+(wektor[a] - srednia)*(wektor[a] - srednia);
  50.                 a++;
  51.  
  52.  
  53.             } while (a < ilosc);
  54.  
  55.             odchylenie = sqrt(suma1 / ilosc);
  56.  
  57.             cout << "odchylenie standardowe= " << odchylenie << endl;
  58.  
  59.             int c = 0;
  60.             while (c < ilosc)
  61.             {
  62.                 if (wektor[c] > srednia+0.2*srednia)
  63.                 {
  64.                     cout << c + 1 << " Element wektora jest wiekszy od sredniej o 20%" << endl;
  65.                 }
  66.                 c++;
  67.             }
  68.            
  69.  
  70.  
  71.  
  72.  
  73.  
  74.        
  75.  
  76.  
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement