-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase2.cpp
More file actions
61 lines (49 loc) · 962 Bytes
/
Copy pathBase2.cpp
File metadata and controls
61 lines (49 loc) · 962 Bytes
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
#include<stdio.h>
#include<math.h>
int main()
{
int b1=0,b2=0;
char ques[80];
char ans[80];
int count=0,i=0,equ=0,dec=0,c=0,count2=0;
printf("Enter the original base : ");
scanf("%d",&b1);
printf("Enter the question : ");
scanf("%s",ques);
printf("Enter the final base : ");
scanf("%d",&b2);
for(count=0;ques[count]!='\0';count++);
count2=count;
count-=1;
while(count>=0)
{
if(ques[count]>='0' && ques[count]<='9')
equ=ques[count]-48;
else if(ques[count]>='A' && ques[count]<='Z')
equ=ques[count]-55;
dec+=equ*pow(b1,c);
c++;
count--;
}
/* printf("The question in decimal is : %d ",dec); */
int rem=0,q=0;
while(dec!=0)
{
rem=dec%b2;
if(rem>=10)
{
ans[q]=rem+55;
}
else
{
ans[q]=rem+48;
}
dec/=b2;
q++;
}
int j=0;
printf("The answer in required base is : ");
for(j=q-1;j>=0;j--)
printf("%c",ans[j]);
return 0;
}