Look here for a complete description of the problem. Your code should follow the coding standards,
good names, spacing, easy on the eyes...etc. Make sure you handle all test case and
boundaries. Good Luck, and happy coding. Although this is a C++ forum, it would be nice to
see some different language used to solve this, but not necessary though.

Member Avatar for 1stDAN

Hi
I have just got this solution:

#include <iostream>
using namespace std;
unsigned long int reversi(unsigned long int n)
{unsigned long int r=0; unsigned short f;
for(;n;n/=10)if(((f=n%10)!=0)||(r!=0))r=10*r+f;return r;}
int main(){
unsigned long int x, y;
cout <<"1st number:   "; cin>>x;
cout <<"2nd number:   "; cin>>y;
cout <<"Reversed sum: "<<reversi(reversi(x)+reversi(y))<<endl;
return 0;}
/*
1st number:   0012003400
2nd number:   1230000000
Reversed sum: 243034
*/

I know that the order of the two predicates in if statement could made problems on other c++ compilers. I am using gnu cpp. I have assumed that the order of processing if is from left to right. If this is not true, f=n%10 must be computed first outside of if statement, for example: {f=n%10;if((f!=0)||(r!=0))r=10*r+f;}

Is this appropriate?

Member Avatar for iamthwee

Cool... I was thinking about having the input answer as a string. Remove the trailing zeros (by creating a trim function) reversing it then converting it to an integer.

But I like your solution better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.