how do i reverse a number which starts with zero in c ? like 000021 to 120000 reverse a number which starts with zero
#include <iostream>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--) {
int n, l;
cin >> n;
while (n != 0) {
l = n % 10;
cout << l;
n /= 10;
if (n != 0)
{
cout << " ";
}
}
cout << endl;
}
return 0;
}
CodePudding user response:
you need to take input number as string.
- reverse the input string.
string s = "00012";
string str="";
for(int i=s.size()-1;i>=0;i--){
str =s[i];
}
cout<<stoi(str);