Advertisement
SteelK

Untitled

May 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include<cstring>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. unsigned int one_max(int *in_mas, size_t in_dlina) {
  11.     unsigned int a = 0, max = 0, b = 0;
  12.     max = in_mas[0];
  13.     for (unsigned int i = 1; i < (in_dlina); i++) {
  14.         a = in_mas[i];
  15.         if (a>max) {
  16.             max = a;
  17.             b = i;
  18.         }
  19.  
  20.     }
  21.     return b;
  22. }
  23.  
  24. unsigned int one_maxrecursia(int *in_mas, size_t in_dlina) {
  25.     unsigned int a = 0, max = 0, b = 0;
  26.     if (in_dlina <= 1) {
  27.         return 0;
  28.     }
  29.     return one_maxrecursia(in_mas, in_dlina);
  30. }
  31. //return b;
  32. //}
  33.  
  34. unsigned int min_rasnost_modul(int *in_mas, unsigned int in_dlina) {
  35.     unsigned int a = 0, min = 0;
  36.     min = abs(abs(in_mas[1]) - abs(in_mas[0]));
  37.     for (unsigned int i = 1; i < (in_dlina - 1); i++)
  38.     {
  39.         a = abs(abs(in_mas[i + 1]) - abs(in_mas[i]));
  40.         if (a<min)
  41.             min = a;
  42.     }
  43.     return min;
  44. }
  45.  
  46. int main() {
  47.     setlocale(0, "");
  48.     int mas1[] = { 1,2,3,4,5 };
  49.     int mas2[] = { -9,8,4 };
  50.     int mas3[] = { 2,2,8,8 };
  51.     if (
  52.         (one_max(mas1, 5) == 4)
  53.         &&
  54.         (one_max(mas2, 3) == 1)
  55.         &&
  56.         (one_max(mas3, 4) == 2)
  57.         &&
  58.         (min_rasnost_modul(mas1, 5) == 1)
  59.         &&
  60.         (min_rasnost_modul(mas2, 3) == 1)
  61.         &&
  62.         (min_rasnost_modul(mas3, 4) == 0)
  63.         )
  64.     {
  65.         cout << "Good" << endl;
  66.         return 0;
  67.     }
  68.     cout << "Bad" << endl;
  69.  
  70.     cout << (one_max(mas1, 5)) << endl;
  71.     cout << (one_max(mas2, 3)) << endl;
  72.     cout << (one_max(mas3, 4)) << endl;
  73.     cout << (one_max(mas1, 5)) << endl;
  74.     cout << (one_max(mas2, 3)) << endl;
  75.     cout << (one_max(mas3, 4)) << endl;
  76.     return 1;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement