Write a function that takes an integer and reverses the digits. The function returns the reversed number to main. Here is the prototype for this function. Write main() to test this function. Use only int data type and arithmetic to solve this problem.

Respuesta :

Answer:

The prototype part missing has been assumed to be:

int reverseNum (int num);

Code:

#include <iostream>

using namespace std;

int reverseNum(int num);

int main()

{

int num=0,result=0;

cout<<"Enter the number:";

cin>>num;

result=reverseNum(num);

cout<<"The reversed number :"<<result<<endl;

return 0;

}

int reverseNum(int num)

{

int temp=0,digit=0;

for(num;num>0;num=num/10)

{

digit=num%10;

temp=temp*10+digit;

}

return temp;

}

Explanation:

ACCESS MORE