Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. int getReverseOddDigit(int a){
  2.     int count = 1, count1 = 0, count2 = 0;
  3.     int b1 = 0, b2 = 0, b = 0, tempB;
  4.     bool isNegative = false;
  5.    
  6.     if(a < 0) {
  7.         isNegative = true;
  8.         a = -a;
  9.     }
  10.    
  11.     do {
  12.         if(count % 2){
  13.             b1 += (a % 10) * pow(10, count1);
  14.             count1++;
  15.         } else {
  16.             b2 += (a % 10) * pow(10, count2);
  17.             count2++;
  18.         }
  19.        
  20.         count++;
  21.        
  22.         a /= 10;
  23.        
  24.     } while(a > 10);
  25.    
  26.     if(count % 2){
  27.         b1 += (a % 10) * pow(10, count1);
  28.         tempB = b1;
  29.     } else {
  30.         b2 += (a % 10) * pow(10, count2);
  31.         tempB = b2;
  32.     }
  33.  
  34.    while(tempB)
  35.    {
  36.        b = b*10 + tempB%10;
  37.        tempB /= 10;
  38.    }
  39.    
  40.    return isNegative ? -b : b;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement