Advertisement
kxcoze

lab22_7_1

Sep 6th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     setlocale(LC_ALL, "rus");
  9.     srand(time(NULL));
  10.  
  11.     int n, data[100], k1;
  12.     cout << "Введите n: ";
  13.     cin >> n;
  14.  
  15.     cout << "Исходный массив: " << endl;
  16.     for (int i = 0; i < n; i++) {
  17.         data[i] = rand() % 20 - 10;
  18.         cout << data[i] << ' ';
  19.     }
  20.     cout << endl;
  21.  
  22.     cout << "Введите k1: ";
  23.     cin >> k1;
  24.  
  25.     for (int i = 0; i < n; i++) {
  26.         if (data[i + 1] < 0)
  27.             data[i] = k1;
  28.         cout << data[i] << ' ';
  29.     }
  30.     cout << endl;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement