Advertisement
Evgeniy175

Untitled

Dec 21st, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include "time.h"
  3. using namespace std;
  4. double fmax(int r, ...)
  5. {
  6.     int i, max, *f;
  7.     double max1, *fd;
  8.     int n = *(&r + 1);
  9.     max = -999;
  10.     max1 = -999;
  11.     if (r == 0)
  12.     {
  13.         f = &r + 2;
  14.         for (i = 0; i < n; i++)
  15.         {
  16.             if (*(f + i) > max) max = *(f + i);
  17.         }
  18.         return max;
  19.     }
  20.     if (r == 1)
  21.     {
  22.         fd = (double *)(&r + 2);
  23.         for (i = 0; i < n; i++)
  24.         {
  25.             if (*(fd + i) > max1) max1 = *(fd + i);
  26.         }
  27.         return max1;
  28.     }
  29.     return 0;
  30. }
  31. int main()
  32. {
  33.     setlocale(LC_CTYPE, "Rus");
  34.     srand((unsigned)time(NULL));
  35.     int i, a[15];
  36.     double b[10], bb, cc, c[5];
  37.     cout << "Массив int:\n";
  38.     for (i = 0; i < 15; i++)
  39.     {
  40.         a[i] = rand() % 99 - rand() % 99;
  41.         cout << a[i] << ' ';
  42.     }
  43.     cout << "\n\nМассив double:\n";
  44.     for (i = 0; i < 10; i++)
  45.     {
  46.         bb = ((rand() % 10000 + 1) / (rand() % 10 + 1));
  47.         b[i] = rand() % 99 - rand() % 99 + bb/100;
  48.         cout << b[i] << "  ";
  49.     }
  50.     cout << "\n\n2 массив double:\n";
  51.     for (i = 0; i < 5; i++)
  52.     {
  53.         cc = ((rand() % 100000 + 1) / (rand() % 10 + 1));
  54.         c[i] = rand() % 99 - rand() % 99 + cc / 10000;
  55.         cout << c[i] << "  ";
  56.     }
  57.     cout << "\n\nmax в int: " << fmax(0, 15, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14]);
  58.     cout << "\nmax в double: " << fmax(1, 10, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9]);
  59.     cout << "\nmax в double 2: " << fmax(1, 5, c[0], c[1], c[2], c[3], c[4]) << '\n';
  60.     system("pause");
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement