#include
#include
#include
using namespace std;
int rev(int n)
{
char buf[100];
sprintf(buf, "%d", n);
int lastdigits = atoi(buf+1);
int firstdigit = buf[0]-'0';
if (n < 10) return n;
return firstdigit + 10 * rev(lastdigits);
}
int main()
{
cout << rev(123) << endl;
return 0;
}
No comments:
Post a Comment