Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hi how can i get numbers from number (like this : 731===>[7,3,1]) with recursive function it help me a lot tanks

here i can use down methode to do this

get a hole number (192)============> (1,9,2)

i’m gonna be gratfull

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream> // I Know This way

using namespace std;

int argam(int n);
int main()
{
    int a;
    cout << "Please enter num : ";
    cin >> a;
    argam(a);
}

int argam(int n)
{

    do
    {
        cout << n % 10 << "\n";
        n /= 10;
    } while (n > 0);
}

5
4
3

get same answer with recursive function

>Solution :

It’s even shorter when done recursively:

void argam(int n)
{
    if (n == 0) return; // end condition for the recursion
    cout << n % 10 << "\n"; // print 1 digit
    argam(n / 10); // call the same function again without that digit
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading