int main (void)
{
int op, i = 0, y = 0
char arr[20]
printf ("\n------------------------------------------------------")//输出菜单
printf ("\n 1.Octal convert decimal")
printf ("\n 2.Hex converted to a decimal number")
printf ("\n 3.Binary conversion to a decimal number")
printf ("\n------------------------------------------------------")
printf ("\nPlease input a number and choose a operating:")
scanf ("%s%d", arr, &op)//输入数字以及 *** 作
switch (op)
{
case 1:while (arr[i])//八进制转换为十进制
{
y = y * 8 + arr[i] - '0'
i++
}
case 2:while (arr[i])//十六进制转换为十进制
{
y = y * 16 + arr[i] - '0'
i++
}
case 3:while (arr[i])//二进制转换为十进制
{
y = y * 2 + arr[i] - '0'
i++
}
}
printf ("The result is %d", y)//输出
return 0
}
给你打个简单的,我已经测试了,
#include<stdio.h>
void main()
{
int a
printf("请输入一个十进制数\n")
scanf("%d",&a)
printf("该数的十六进制是:%x\n",a)
printf("该数的八进制是:%o\n",a)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)