Write a function, reverseDigit , that takes an integer as a parameter and return
ID: 3622287 • Letter: W
Question
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.... 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.... 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....
Explanation / Answer
please rate - thanks
#include<iostream>
using namespace std;
int reverseDigit(int);
int main()
{int number,reversed;
cout<<"Enter a number ";
cin>>number;
reversed=reverseDigit(number);
cout<<"Reversed "<<number<<" is "<<reversed<<" ";
system("pause");
return 0;
}
int reverseDigit(int n)
{int newnum=0;
int sign = 1;
if(n<0)
{sign=-1;
n*=sign;
}
while(n>0)
{newnum=newnum*10+n%10;
n=n/10;
}
return newnum*sign;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.