69 679
Assignments Done
Successfully Done
In February 2019

Answer to Question #71813 in C++ for raja haseeb

Question #71813
Q 4. Write a function, reverseDigit that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(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.
Expert's answer
#include <iostream>

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

int main()
cout << reverseDigit(12345) << "\n";
cout << reverseDigit(5600) << "\n";
cout << reverseDigit(7008) << "\n";
cout << reverseDigit(-532) << "\n";

return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions