English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how can i write a c++ 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 .. and the value of reverseDigit(-532) is -235..

2007-05-06 22:55:13 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

int reverse_Digits(int rev) //Reverse the digits of the input
{
int num1 = rev, //Assigning constant from int main() to variable
rnum = 0, //Variable to hold reversed number
digit; //Holds number extracted by % function to be added to rnum

while (num1 > 0) //While loop to reverse digits
{
rnum *= 10;
digit = num1 % 10;
rnum += digit;
num1 /= 10;
}
return rnum;

}

2007-05-06 23:01:27 · answer #1 · answered by jok3r 4 · 0 0

fedest.com, questions and answers