-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodigo.cpp
76 lines (52 loc) · 1.35 KB
/
codigo.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
int main () {
int N, Qualb, IrparaB, contador=0, teste;
char c;
int resp[1000];
string conv;
cout<<"Qual numero voce quer converter?"<<endl;
cin>>N;
int sep=N;
cout<<"Qual sua base?"<<endl;
cin>>Qualb;
cout<<"Deseja ir para qual base?"<<endl;
cin>>IrparaB;
int cont=0;
if(Qualb==10){
while(N!=0){
cout<<N<<" / "<<IrparaB<<" = "<<N/IrparaB<<", resto "<< N%IrparaB<<endl;
resp[cont]=N%IrparaB;
N=N/IrparaB;
cont++;
}
for(int i=cont-1; i>=0; i--){
contador = 0;
if(IrparaB>10){
if(resp[i]>9){
if(resp[i]<IrparaB)
resp[i]+=55;
teste=resp[i];
c=teste;
cout<<c;
contador=1;
}
}
if(contador==0) cout<<resp[i];
}
}
else if(IrparaB==10){
while(sep!=0){
resp[cont]=sep%10;
sep=sep/10;
cont++;
}
for(int i=cont-1; i>=0; i--){
contador+=resp[i]*pow(Qualb, i);
cout<<resp[i]<<"*"<<Qualb<<"^"<<i;
if(i!=0)
cout<<" + ";
}
cout<<" = "<<contador;
}
}