Phoenix_x

Untitled

Mar 28th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. //???????? ??????????:
  8. int index = 0;
  9. int arr[10]; //??????????? ????? ? ???????? ? 10 ?????
  10.  
  11. void fillArray(int arr[], string &numberAsString);
  12. void printArray(int arr[]);
  13.  
  14. void main()
  15. {
  16.     //1. ?????????, ?? ?????????? ????? ? ?????????? (?? - ?????? ?? 0 ? ????)
  17.     int number;
  18.  
  19.     while (true)
  20.     {
  21.         cout << "Number: ";
  22.         cin >> number;
  23.  
  24.         if (number < 1)
  25.         {
  26.             cout << "Input must be bigger number than one." << endl;
  27.         }
  28.         else {
  29.             break; //??? ? ??????? ???????, ???????? ??????, ????? ?? ??????
  30.         }
  31.     }
  32.  
  33.     //2. ??????????? ?? ??????? ???? ??????, ???????? ?? ???????
  34.     string numberAsString = to_string(number);
  35.     fillArray(arr, numberAsString); //????????? ?? ?????????? ???????
  36.  
  37.  
  38.     //3.?????????? ?? ??????:
  39.     printArray(arr);
  40. }
  41.  
  42. void fillArray(int arr[], string &numberAsString)
  43. {
  44.     if (numberAsString != "")//??? ??????? ?? ? ???????? ??? ????? (???? ???????)
  45.     {
  46.         int firstDigit = numberAsString[0] - 48; //-48 ?????? ASCII
  47.         numberAsString.erase(0, 1); // ????? ??????? ????? ?? ???????
  48.  
  49.         arr[index] = firstDigit;
  50.         index++;
  51.         fillArray(arr, numberAsString);
  52.     }
  53. }
  54.  
  55. void printArray(int arr[])
  56. {
  57.     for (int i = 0; i < index; i++)
  58.     {
  59.         cout << "a[" << i << "] = " << arr[i] << endl;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment