Guest User

Untitled

a guest
Apr 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. using namespace std;
  5.  
  6. void Init(int [], int);
  7. void alfa(int [], int, double &);
  8. void Tisk(int [], int);
  9.  
  10. int minimum(int [], int);
  11.  
  12. int main() {
  13.  
  14.     const int N = 8; // velikost pole
  15.     int P[N]; // deklarace pole
  16.     double alfa_x; // tvoje alfa
  17.  
  18.     srand(time(NULL));
  19.  
  20.     Init(P, N); // napln pole nahodnymi cislami
  21.     Tisk(P, N); // vytiskni pole
  22.  
  23.     alfa(P, N, alfa_x); // ke kazdemu lichemu prvku pricitej najmensi cislo z pole
  24.     Tisk(P, N); // vytiskni pole
  25.  
  26.     cout << endl << "Alfa: " << alfa_x << endl; // vytiskni x (nejmensi cislo v poli)
  27.     system("PAUSE");
  28.  
  29.     return 0;
  30.  
  31. }
  32.  
  33. void Tisk(int pole[], int delkaPole) {
  34.  
  35.     for(int j=0; j < delkaPole; j++) {
  36.         cout << pole[j] << " ";
  37.     }
  38.     cout << endl;
  39.  
  40. }
  41.  
  42. void Init(int pole[], int delkaPole) {
  43.  
  44.     for(int j=0; j < delkaPole; j++) {
  45.         pole[j] = rand() % delkaPole + 1;
  46.     }
  47.  
  48.  
  49. }
  50.  
  51. void alfa(int pole[], int delkaPole, double &param_alfa) {
  52.  
  53.  
  54.  
  55.     param_alfa = minimum(pole, delkaPole);
  56.  
  57.     for(int j=0; j < delkaPole; j++) {
  58.  
  59.         if (j % 2 == 1) {
  60.             pole[j] = pole[j] + param_alfa;
  61.         }
  62.  
  63.  
  64.  
  65.     }
  66.  
  67.  
  68. }
  69.  
  70. int minimum(int pole[], int delkaPole) {
  71.     int min;
  72.     min = pole[0];
  73.  
  74.     for(int i=0; i < delkaPole; i++) {
  75.  
  76.         if (min > pole[i]) {
  77.             min = pole[i];
  78.         }
  79.  
  80.     }
  81.     return min;
  82.  
  83. }
Add Comment
Please, Sign In to add comment