Advertisement
Guest User

homework_8

a guest
Nov 18th, 2019
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>;
  3. using namespace std;
  4. void PrintArray(int* arrA, int k)
  5. {
  6.     for (int i = 0; i < k; i++)
  7.         cout << arrA[i] << " ";
  8.     cout << endl;
  9. }
  10. int main()
  11. {
  12.     int n, k;
  13.     cout << "Enter n" << endl;
  14.     cin >> n;
  15.     cout << "Enter k" << endl;
  16.     cin >> k;
  17.     int* numbers = new int[k];
  18.     int* multipliers = new int[k];
  19.     for (int i = 0; i < k; i++) {
  20.         numbers[i] = 1;
  21.         multipliers[i] = 1;
  22.     }
  23.     PrintArray(numbers, k);
  24.     int i = k - 1;
  25.     while (i >= 0)
  26.     {
  27.         if (numbers[i] == n && multipliers[i] > 0 || numbers[i] == 1 && multipliers[i] < 0) {
  28.             multipliers[i] *= -1;
  29.             i--;
  30.         }
  31.         else {
  32.             numbers[i] += 1 * multipliers[i];
  33.             i = k - 1;
  34.             PrintArray(numbers, k);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement