0

# include<string.h>

void is_trans(char *number,int type);
void is_trans2(int sum);

void main()
{
char number[1000];
int type;

``````printf("请输入你要输入的数字：");
gets(number);

printf("请输入你要输入的数的进制：");
scanf("%d",&type); //为什么这里的scanf和前面的gets互换位置之后就只能输入scanf的，而gets直接被跳过了？？？

is_trans(number,type);``````

}

void is_trans(char *number,int type)
{
int i,len,sum,q;
len = strlen(number);
sum = 0;

``````for (i = 0;number[i] != '\0';i++)
{
if (type == 8||10)
break;

switch (number[i])
{
case 'A':   number[i] = 10;break;
case 'B':   number[i] = 11;break;
case 'C':   number[i] = 12;break;
case 'D':   number[i] = 13;break;
case 'E':   number[i] = 14;break;
case 'F':   number[i] = 15;break;

}

}
for (i = 0;number[i] != '\0';i++)
{
q = len-i-1;
sum = sum + (number[i]*pow(type,q));//为什么当输入的是7和8时，这里的sum会变成55？？？

}

is_trans2(sum);``````

}

void is_trans2(int sum)
{
int i,a[1000],n,p;

``````n = 0;

for (i = 0;sum != 0;i++)
{
p = sum % 2;
sum = sum / 2;
a[i] = p;
n++;

}

for (i = n - 1;i >= 0;i--)
{
printf("%d",a[i]);
}``````

}

shmily涂 | 初学一级 | 园豆：66

0

wwr01 | 小虾三级 |园豆：601 | 2019-11-14 09:22

shmily涂 | 园豆：66 (初学一级) | 2019-11-14 22:43

您需要登录以后才能回答，未注册用户请先注册