Home > front end >  Finding reverse of number in c with arrays
Finding reverse of number in c with arrays

Time:11-26

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.

CodePudding user response:

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

and j<=i will be j<i

CodePudding user response:

did you try:

cout<< reverse( number);
  •  Tags:  
  • c
  • Related