C base conversion code sharing
- 2020-04-02 03:07:53
- OfStack
The code is simple, the functionality is simple, and there's no more nonsense here
#include<stdio.h>
int main()
{
char ku[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int zh[32],i=0,w,j;
long int b,y;
printf(" Please enter a decimal number that I can convert to 2~16 Arbitrary base number: n");
scanf("%d",&y);
b=y;
printf(" Please enter the base to convert to :");
scanf("%d",&w);
printf("n");
do
{
zh[i]=y%w;
i++;
y=y/w;
}
while(y!=0);
printf(" Let's do the decimal %ld convert %d Into the system :",b,w);
for(i--;i>=0;i--)
{
j=zh[i];
printf("%c",ku[j]);
}
printf("n");
return 0;
}
The above is all the content of this article, I hope you can enjoy it.