-
Notifications
You must be signed in to change notification settings - Fork 0
/
num_flip.cpp
31 lines (29 loc) · 925 Bytes
/
num_flip.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// ######### MULTIPLE DIGIT FLIPPING ###########
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int arr[5] = {13,12,37,43539,512};
for(int i = 0; i < 5; i++){
int len;
len = log10(arr[i]); // 2
int rev=0, temp=0, j=0, holder=0,rem =0;
do{
(!temp) ? holder = arr[i] : holder = temp; // 512 51 5
rem = holder % 10; // 2 1 5
temp = holder / 10; // 51 5 0
rev += (rem*(pow(10,len-j))); // 200 + 10 + 5
j++; // 0 1 2
}while(temp);
cout << rev << endl;
//######## two digit flipping ############
// for(int j = 0; j <len; j++){
// holder = arr[i];
// rem = holder % 10;
// holder = holder / 10;
// rev = rem*(pow(10,len-j)) + holder;
// cout << rev << endl;
// }
}
return 0;
}