Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6ed15c5

Browse files
Merge pull request fnplus#254 from abhijitmanatkar/base_conversion_c
added base conversion program in c
2 parents 1aa97dc + 23d7813 commit 6ed15c5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<stdio.h>
2+
#include<math.h>
3+
4+
long long int to_decimal(long long int n, int b){
5+
long long int dec = 0;
6+
long long int i = 1;
7+
while(n > 0){
8+
dec += (n % 10) * i;
9+
i *= b;
10+
n /= 10;
11+
}
12+
return dec;
13+
}
14+
15+
long long int to_base(long long int dec, int b){
16+
long long int m = 0;
17+
long long int i = 1;
18+
while(dec > 0){
19+
m += (dec % b) * i;
20+
i *= 10;
21+
dec /= b;
22+
}
23+
return m;
24+
}
25+
26+
int main(){
27+
long long int n;
28+
int x,y;
29+
printf("Enter number and base that it is in:\n");
30+
scanf("%lld %d", &n, &x);
31+
printf("Enter base to convert to:\n");
32+
scanf("%d", &y);
33+
printf("%lld \n", to_base(to_decimal(n, x), y));
34+
return 0;
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /