Advertisement
Fakher_AldeenOdeh

swap First Digit with Last Digit

Mar 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, first, last, sum, digits, nn, a, b;
  8.     cout << "\n\n Find the number after swapping the first and last digits:\n";
  9.     cout << "-------------------------------------------------------------\n";
  10.     cout << " Input any number: ";
  11.     cin >> n;
  12.     if (n % 2 == 0) {
  13.         digits = log10(n);
  14.         first = n / pow(10, digits);
  15.         last = n % 10;
  16.         a = first * (pow(10, digits));
  17.         b = n % a;
  18.         n = b / 10;
  19.         nn = last * (pow(10, digits)) + (n * 10 + first);
  20.         cout << " The number after swaping the first and last digits are: " << nn << endl;
  21.     }
  22.  
  23.     system("pause");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement