Write a program which takes a 9-digit number input from user, converts it into its reverse
No loops you can use only conditional structures.
#include <iostream>
#include <string>
using namespace std;
string rvrs(long int val)
{
static string res = "";
if (val > 0)
{
char tmp;
tmp = '0' + val % 10;
res += tmp;
rvrs(val / 10);
}
return res;
}
int main()
{
long int value;
cout << "Please, enter a 9-digit number: ";
cin >> value;
long int res = stoi(rvrs(value));
cout << "Reversed result is " << res;
}
Comments
Leave a comment