/* ************************************************************************
* 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;
}
这里是运行结果: