Advertisement
AnyaAS

Ukazateli_3_1

Mar 3rd, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. // Даны два массива: А[M] и B[N] (M и  N вводятся с клавиатуры).
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <time.h>
  6. #include <stdlib.h>
  7. using namespace std;
  8.  
  9. int Vvod_chisel(char *);
  10. void Init(int *, int, char *);
  11. void Print(int *, int, char *);
  12.  
  13. int _tmain(int argc, _TCHAR* argv[])
  14. {
  15.     setlocale(LC_ALL, "Russian");
  16.     int n, m, *A, *B;
  17.     do
  18.     {
  19.         m = Vvod_chisel("Введите размер первого массива = ");
  20.         n = Vvod_chisel("Введите размер второго массива = ");
  21.     } while (n <= 0 && m <= 0);
  22.     A = new int[m];
  23.     B = new int[n];
  24.     srand(time(NULL));
  25.     Init(A, m, "Создание первого массива...");
  26.     Init(B, n, "Создание второго массива...");
  27.     Print(A, m, "Созданный первый массив");
  28.     Print(B, n, "Созданный второй массив");
  29.     delete[]A;
  30.     delete[]B;
  31. }
  32. int Vvod_chisel(char *ms)
  33. {
  34.     cout << ms;
  35.     char str[10];
  36.     cin.getline(str, 10);
  37.     return atoi(str);
  38. }
  39. void Init(int *mas, int n, char *ms)
  40. {
  41.     cout << ms << endl;
  42.     for (int i = 0; i < n; *mas++ = rand() % 30 + -10, i++);
  43. }
  44. void Print(int *mas, int n, char *ms)
  45. {
  46.     cout << ms << endl;
  47.     for (int i = 0; i < n; cout.width(3), cout << *mas++, i++);
  48.     cout << endl;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement