Advertisement
AnyaAS

Ukazateli_4_1

Mar 3rd, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7. void Init(int *mas, int size);
  8. void Print(int *mas, int size);
  9. int Funk(int *mas, int size, int value);
  10.  
  11. int _tmain(int argc, _TCHAR* argv[])
  12. {
  13.     setlocale(LC_ALL, "Russian");
  14.     int size = 10;
  15.     int *mas = new int[size];
  16.     Init(mas, size);
  17.     Print(mas, size);
  18.     int value;
  19.     cout << "Введите число -> ";
  20.     cin >> value;
  21.     cout << "Результат " << Funk(mas, size, value) << endl;
  22. }
  23.  
  24. void Init(int *mas, int size)
  25. {
  26.     for (int i = 0; i < size; *mas++ = rand() % 20 + -6, i++);
  27. }
  28. void Print(int *mas, int size)
  29. {
  30.     cout << "Массив" << endl;
  31.     for (int i = 0; i < size; cout << *mas++ << " ", i++);
  32.     cout << endl;
  33. }
  34. int Funk(int *mas, int size, int value)
  35. {
  36.     bool b = false;
  37.     for (int i = 0; i < size; i++)
  38.     {
  39.         if (*(mas + i) == value)
  40.         {
  41.             b = true;
  42.             return *(mas + i);
  43.             break;
  44.         }
  45.     }
  46.     if (b == false)
  47.     {
  48.         return 0;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement