Answer to Question #312131 in C++ for Ali

Question #312131

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.


1
Expert's answer
2022-03-15T16:46:16-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment