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

Finding reverse of number in c++ with arrays

I am basically trying to find reverse of the number entered by user :
This is my main.cpp code

   int number=0;
   cout<< " enter a number";
   cin>>number;
   reverse( number);

this is my function .cpp code

 int reverse( int number){
    int last=0;
    int i=0;
    int array1[10]={0} ;
    int check=number;
    while ( check!=0){
        last=check%10;
        array1[i]=last;
        i++;
        check=number/10;
    }
    for (int j = 0; j <= i; ++j) {
        cout<<array1[j];

    }
    return 0;

}

When i run it on my cygwin, it only asks me to enter a number then does not gives any ouput.
what should i correct so that i can get reverse of number.

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

>Solution :

check=number/10 will be check=check/10

and j<=i will be j<i

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