belongs to collection: C++ Language Loop Programs with Examples
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
#include <iostream> #include <math.h> using namespace std; int main() { int num, last, first, temp, swap, count = 0; //Reading a number from user cout<<"Enter any number:"; cin>>num; temp = num; last = temp % 10; count = (int)log10(temp); while(temp>=10) { temp /= 10; } first = temp; swap = (last * pow(10, count) + first) + (num - (first * pow(10, count) + last)); cout<<"Last Digit: "<<last<<endl; cout<<"First Digit: "<<first<<endl; cout<<num<<" is swapped to "<<swap; return 0; }
Result:
Enter any number:123456
Last Digit: 6
First Digit: 1
123456 is swapped to 623451
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
Result:
Enter any number:123456
Last Digit: 6
First Digit: 1
123456 is swapped to 623451
need an explanation for this answer? contact us directly to get an explanation for this answer