Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
Introduction to C++, Kevin Kelly Kelly Front Page  | C++ Course Guide | C++ Assignments | C++ Info

Assignment 12: Reversing a number

due Wednesday 3/13

Write a function twodigitreverse that reverses the digits of a two-digit integer. For example, if the input is 24, the output would be 42.

Use this main program to test your function:

int main()
{
	cout << "24 reversed is " << twodigitreverse(24) << "." << endl;
	cout << "19 reversed is " << twodigitreverse(19) << "." << endl;
	cout << "80 reversed is " << twodigitreverse(80) << "." << endl;
	cout << "77 reversed is " << twodigitreverse(77) << "." << endl;
	return 0;
}



Extensions

For 5 pts.: Add output formatting commands so that the third output value will appear as 08, not just 8.

For 10 pts.: Also write a function reverse that can reverse the order of any integer; for example, reverse(12345) would return the value 54321.