- Code: Select all
#include <cstdlib>
#include <iostream>
using namespace std;
int reverse(int value);
int reverse (int argc, char *argv[]);
int main()
{ //Do not edit anything between this comment and the next comment.
int value;
cout << "Enter a positive integer less than 1000000: ";
cin >> value;
value = reverse(value);
cout << "\nYour integer in reverse order is: " << value;
cout << "\n\n\n";
system("PAUSE");
return EXIT_SUCCESS;
} // Do not edit anything between the previous comment and this one.
int reverse( int value)
{
int sum = 0;
int val;
/*I know 5th and 6 integers goes here but I dont know
and cant find formula to reverse 5th and 6th any help plz*/
val = value / 1000;
sum = val;
value = value - (val * 1000);
val = value / 100;
sum = sum + (val * 10);
value = value - (val * 100);
val = value / 10;
sum = sum + (val * 100);
value = value - (val * 10);
sum = sum + (value * 10000);
return(sum);
}
-- Sun Nov 18, 2012 4:53 pm --
nvm all I figured it out I replaced
- Code: Select all
int sum = 0;
int val;
/*I know 5th and 6 integers goes here but I dont know
and cant find formula to reverse 5th and 6th any help plz*/
val = value / 1000;
sum = val;
value = value - (val * 1000);
val = value / 100;
sum = sum + (val * 10);
value = value - (val * 100);
val = value / 10;
sum = sum + (val * 100);
value = value - (val * 10);
sum = sum + (value * 10000);
return(sum);
With
- Code: Select all
int rev, val;
while (value > 0)
{
val = value % 10;
rev = rev * 10 + val;
value = value / 10;
}
return(rev);
but thx anyways.


