vertexofvortex

matveeva-16

Sep 16th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void fill(int[], int);
  8. int fmax(int[], int);
  9. int fmin(int[], int);
  10.  
  11. int main() {
  12.     setlocale(0, "");
  13.     srand(time(0));
  14.  
  15.     int P[13];
  16.     int B[9];
  17.  
  18.     cout << "Массив P: ";
  19.     fill(P, 13);
  20.     cout << "Массив B: ";
  21.     fill(B, 9);
  22.  
  23.     cout << endl << "max(P) = " << fmax(P, 13) << endl;
  24.     cout << "min(P) = " << fmin(P, 13) << endl;
  25.     cout << "max(B) = " << fmax(B, 9) << endl;
  26.     cout << "min(B) = " << fmin(B, 9) << endl;
  27.  
  28.     double Z = ((double)fmax(P, 13) - (double)fmin(P, 13)) / ((double)fmax(B, 9) - (double)fmin(B, 9));
  29.  
  30.     cout << endl << "(max(P) - min(P)) / (max(B) - min(B)) = " << Z << endl;
  31.  
  32.     system("pause");
  33. }
  34.  
  35. void fill(int array[], int length) {
  36.     for (int i = 0; i < length; i++) {
  37.         array[i] = rand() % 100 + 1;
  38.         cout << array[i] << " ";
  39.     }
  40.     cout << endl;
  41. }
  42.  
  43. int fmax(int array[], int length) {
  44.     int max = array[0];
  45.     for (int i = 0; i < length; i++) {
  46.         if (array[i] > max) {
  47.             max = array[i];
  48.         }
  49.     }
  50.  
  51.     return max;
  52. }
  53.  
  54. int fmin(int array[], int length) {
  55.     int min = array[0];
  56.     for (int i = 0; i < length; i++) {
  57.         if (array[i] < min) {
  58.             min = array[i];
  59.         }
  60.     }
  61.  
  62.     return min;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment