kuchnahi
kuchnahi

Reputation: 51

Reversing number in c++ with arrays

I am trying to find the reverse of the number entered by the 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;

}

It only asks me to enter a number then does not give any output. what should I correct?

Upvotes: 0

Views: 259

Answers (2)

arbitrary_A
arbitrary_A

Reputation: 373

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

and j<=i will be j<i

Upvotes: 2

DSMSTHN
DSMSTHN

Reputation: 40

did you try:

cout<< reverse( number);

Upvotes: 0

Related Questions