Guest User

Untitled

a guest
Apr 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <iomanip>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. const int M = 100; //MAXIMUM
  10.  
  11. void Init(double P[], int N)
  12. {
  13.     srand(time(0));
  14.     for(int i=0; i<N; i++)
  15.     {
  16.         P[i] = rand() % M;
  17.     }
  18. }
  19. void Tisk(double P[], int N)
  20. {
  21.     for(int j=0; j<N; j++)
  22.     {
  23.         cout<<setfill(' ')<<setw(3)<<j<<"=";
  24.         cout<<setfill(' ')<<setw(5)<<P[j];
  25.         cout<<endl;
  26.     }
  27.     cout<<endl;
  28. }
  29. double Alfa(double P[], int N)
  30. {
  31.     double Min=M,Max=0;
  32.     for(int j=0; j<N; j++)
  33.     {
  34.         if(P[j]>Max) Max=P[j];
  35.         if(P[j]<Min) Min=P[j];
  36.     }
  37.     return sqrt((Max-Min)*(Max-Min));
  38. }
  39. void Filtr(double P[], int N, double O)
  40. {
  41.     for(int j=0; j<N; j++)
  42.     {
  43.         P[j]=P[j]-O;
  44.     }
  45. }
  46.  
  47. int main()
  48. {
  49.     const int N = 8;
  50.     double P[N];   
  51.    
  52.     Init(P,N); 
  53.     cout<<"Nahodne hodnoty: "<<endl<<endl; 
  54.     Tisk(P,N);
  55.    
  56.     double O=Alfa(P,N);
  57.     cout<<endl<<"Parametr filtru: "<<O<<endl<<endl<<endl;
  58.  
  59.     Filtr(P,N,O);  
  60.     cout<<"Vyfiltrovane hodnoty: "<<endl<<endl;
  61.     Tisk(P,N);
  62.  
  63.     system("pause");   
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment