这是个数值转换的:就是10进制转2进制,8进制,16进制;
希望大家帮帮忙看看:
源程序在下面:主要问题是子函数调要不起来!
#include <stdio.h>
#define N 30
void transform(int n,int base);
int main()
{
int num,select,flag=1;
printf("input your number!\n");
scanf("%d",num);
while(flag)
{
printf("1----->10 transform 2\n");
printf("2----->10 transform 8\n");
printf("3----->10 transform 16\n");
printf("4----->out");
printf("input your select!\n");
scanf("%d",select);
switch(select)
{
case 1: transform(num,2);
break;
case 2: transform(num,8);
break;
case 3: transform(num,16);
break;
case 4: flag=0;
break;
}
}
}
void transform(int n,int base)
{
int s[N];
int x;
int top=-1;
while(n)
{
x=n%base;
top++;
s[top]=x;
n=n/base;
}
while(top!=-1)
{
if(s[top]<=9)
{ printf("%d",s[top]) ;top--;}
else
{printf("%c",s[top]-10+'A');top--;}
}
}