您的位置:首页 > 其它

将10进制数转换为任意进制数进行显示

2011-04-29 10:41 423 查看
/* ************************************************************************
*       Filename:  test.c
*    Description:  将10进制数转换成为其他任意进制数
*        Version:  1.0
*        Created:
*       Revision:  none
*       Compiler:  gcc
*         Author:    wen hao
*        Company:
* ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int M;

void showhex(int n)
{

if(n>(M-1))
{
showhex(n/M);//递归调用
}
printf("%d",n%M);
}

int main(int argc, char *argv[])
{
int n;
if(argc < 2)
{
printf("please input two parament\n");
sleep(1);
return 0;
}
M = atoi(argv[1]);//将第二个参数,转换为int型
while(1)
{
printf("\rplease input Decimal number:");
scanf("%d",&n);
showhex(n);
printf("\n");
}
return 0;
}


这里是运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: