-
Notifications
You must be signed in to change notification settings - Fork 0
/
base5tobase9.cpp
43 lines (40 loc) · 995 Bytes
/
base5tobase9.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
32
33
34
35
36
37
38
39
40
41
42
43
// PROGRAM THAT CONVERTİNG BASE-5 SYSTEM NUMBERS TO BASE-9 SYSTEM.
#include <iostream>
int main(){
int base5,counter=0,digit=0,base10=0;
std::cout << "enter a number in base5 system :" << std::endl;
std::cin >> base5;
int temp=base5;
while(temp>0){
temp/=10;
counter++;
}
temp=base5;
for(int i=0;i<counter;i++){
for(int j=0;j<i;j++){
temp/=10;
}
int exponential=1;
for(int k=0;k<i;k++){
exponential=exponential*5;
}
base10=base10+exponential*(temp%10);
}
std::cout << "this number in base10 system = "<<base10 << std::endl;
counter=0;
temp=base10;
while(temp>0){
temp/=10;
counter++;
}
temp=base10;
std::cout << "this number in base9 system = ";
for(int i=counter;i>0;i--){
for(int j=counter;j>1;j--){
temp=temp/9;
}
std::cout << temp%9 ;
temp=base10;
}
return 0 ;
}