-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Nov 4, 2024
1 parent
e5dad3f
commit ed5551f
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
const char f[]="0123456789ABCDEF"; | ||
void A(int n,int m) | ||
{ | ||
int i=0; | ||
char a[1000]; | ||
while(n) | ||
{ | ||
a[i]=f[n%m]; | ||
n=n/m; | ||
i++; | ||
} | ||
while(i--) | ||
printf("%c",a[i]); | ||
} | ||
|
||
void B(int n,int m) | ||
{ | ||
if(n<m) | ||
{ | ||
if(n<10) | ||
printf("%d",n); | ||
else | ||
printf("%c",n-10+'A'); | ||
} | ||
else | ||
{ | ||
B(n/m,m); | ||
if(n%m<10) | ||
printf("%d",n%m); | ||
else | ||
printf("%d",n%m-10+'A'); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int i,j; | ||
printf("输入数字:\n"); | ||
scanf("%d",&i); | ||
printf("输入要转换的进制:\n"); | ||
scanf("%d",&j); | ||
printf("输出转换后的数字:"); | ||
B(i,j); | ||
printf("\n"); | ||
A(i,j); | ||
system("pause"); | ||
return 0; | ||
} |