Skip to content

Commit

Permalink
Create Decimaltohex.c
Browse files Browse the repository at this point in the history
作用:十进制转十六进制
算法:递归
优点:代码量少
缺点:耗栈内存
  • Loading branch information
errorcode7 committed Nov 15, 2013
1 parent 8eaa20f commit 2b38ece
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Decimaltohex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
#define N 16

char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

void put(int num)
{
int m;

m=num%N;
num=num/N;

if(num>0)
{
put(num);
}
printf("%c",hex[m]);
//printf("%d",m);
}

int main()
{

int num;
printf("input:");
scanf("%d",&num);
printf("output:");
put(num);
printf("\n");
system("pause");
return 0;
}

0 comments on commit 2b38ece

Please sign in to comment.