Hi Guys,
I need to flip an integer's last digit to front and print out new integer:
ie.
Lets says my original integer is 19896 then i like to have a out put something like 61989. Can someone please help me. If not a code then algorithm that follows the same method.
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void flip(double &no)
{
int c=0,s=no%10;
no/=10;
while(pow(10,c)<no) c++;
no+=s*pow(10,c);
}
int main()
{
int no=45867;
flip(no);
cout << no;
return 0;
}
thanks Guys for helping me.
Here is one more thing. How could one fit this integer?
421052631578947368.
What should i use, int, float, double??????
and this is what i'm trying to do:
Lets find a number that is same when you double it and flip the last digit of original number to the front.
ie.
my Original number is 19896, but when i flip last digit it will become 61989 and double the original is (19896*2 = 39792) but the flipped number which is 61989 and doubled number which is 39792 are not EQUAL so it does not work. find me a number that is equal.
@vlad
You also might want to reconsider line 6 of your code. This is where the stringstream might be handy.
There is no need to introduce new headers, template classes and objects when an operation can be simply done with existent operators for a given type. What you are suggesting is called a bad style. There is such a principle as KISS in programming that means Keep It Simple Stuipid
Here is one more thing. How could one fit this integer?
421052631578947368.
Unsigned long long should fit this.
Lets find a number that is same when you double it and flip the last digit of original number to the front.
This is really the same problem as the original one, with another step added to it. And from glancing at your program, looks like you're on the right track. Are you having issues with it?
C:\Users\Jatin\Desktop>g++ -Wall test2.cpp
test2.cpp: In function `int main()':
test2.cpp:17: warning: integer constant out of range
test2.cpp:17: warning: decimal integer constant is so large that it is unsigned