+ 1
Code problems
#include <iostream> #include <vector> static void takeChar(int ch); class Number{ public: void setNum(){ std::cin >> num; } int getNum(){ return num; } private: int num; }; int divide(){ Number *n = new Number; n->setNum(); int number = n->getNum(); int cNum = number; while(number > 0){ number%=10; takeChar(number); number = cNum/10; cNum = number; } return number; } int main() { divide(); return 0; } void takeChar(int ch){ static std::vector<int> chars; chars.push_back(ch); if(divide() < 0){ for(auto v : chars) std::cout << v; } } Memory problem or something.
3 ответов
+ 1
Oleg Storm in your code, I don't understand benifit of recursive call in takeChar function...
can't you make it very simple as below single line in it?
cout << v << endl;
I guess what you have done is calling Divide again from takeChar results into recursive call
+ 1
Ketan, that's it, thanks for help🤗
0
Happy to help