#include
void main()
{
int a,b,d;
char c;
printf("输入如“3*4”或“5+2”的四则运算式:");
scanf("%d%c%d",&a,&c,&b);
switch(c)
{
case'+':d=a+b;break;
case'-':d=a-b;break;
case'*':d=a*b;break;
case'/':d=a/b;break;
}
printf("%d%c%d=%d\n",a,c,b,d);
}
int main(){
int a,b,c[10000],i=0,j=0;
printf("请输入想转换的a进制:a= ");
scanf("%d",&a);
switch (a)
{
case 2:
printf("请输入一个十进制:b= ");
scanf("%d",&b);
do
{
c[i]=b%2;
b=b/2;
i++;
j++;
}
while(b!=1);
c[j]=1;
printf("二进制为: ");
for(i=j;i>=0;i--)
printf("%d",c[i]);
break;
case 8:
printf("请输入一个十进制:b= ");
scanf("%d",&b);
do
{
c[i]=b%8;
b=b/8;
i++;
j++;
}
while(b!=0);
printf("八进制为: ");
for(i=j-1;i>=0;i--)
printf("%d",c[i]);
break;
case 16:
printf("请输入一个十进制:b= ");
scanf("%d",&b);
do
{
c[i]=b%16;
b=b/16;
i++;
j++;
}
while (b!=0);
printf("十六进制为: ");
for(i=j-1;i>=0;i--)
printf("%d",c[i]);break;
default:printf("错误\n");
}
}