Write a function, reverse Digit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverse Digit( 12345) is 54321; the value of reverseDigit (5600) is 65; the value of reverseDigit (7008) is 8007; and the value of reverseDigit (-532) is -235.

Respuesta :

Answer:

This is how you'll write the code in C++ programming language.

Explanation:

using namespace std;

//begin task

int reverseDigit(int val)

{

int res = 0;

while (val != 0)

{

//move digits result to left

res *= 10;

//get last digit value

res += val % 10;

//next digit value

val = val / 10;

}

return res;

}

//end task

//TESING

int main()

{

cout << reverseDigit(12345) << "\n";

cout << reverseDigit(5600) << "\n";

cout << reverseDigit(7008) << "\n";

cout << reverseDigit(-532) << "\n";

return 0;

}

ACCESS MORE