int main()
{
char a[100],b;
long int n;
int i,j,re,num,select,count = 0;
do
{ menu(); //打印出菜单界面
printf("\nPlease select an option : ");
scanf("%d", &select); //输入你的选项
switch (select)
{
case 1://实现加法功能
printf("please input the number(Two digits separated by a space): ");
scanf("%d%d", &i, &j);
printf("%d+%d=%d\n", i, j, num = i + j);
break;
case 2: //实现减法功能
printf("please input the number(Two digits separated by a space): ");
scanf("%d%d", &i, &j);
printf("%d-%d=%d\n", i, j, num = i - j);
break;
case 3:// 实现乘法功能
printf("please input the number(Two digits separated by a space): ");
scanf("%d%d", &i, &j);
printf("%d*%d=%d\n", i, j, num = i*j);
break;
case 4: //实现除法功能
printf("please input the number(Two digits separated by a space): ");
scanf("%d%d", &i, &j);
printf("%d/%d=%d\n", i, j, num = i / j);
break;
case 5: //实现十进制转换2进制
printf("please input the number: ");
scanf("%d",&i);
do{ a[count++]=i%2;i=i/2; }while(i!=0);
for(int z=count-1;z>=0;z--){
printf("%d",a[z]);}
break;
case 6: //实现十进制转换8进制
printf("please input the number: ");
scanf("%d",&i);
do{ a[count++]=i%8;i=i/8; }while(i!=0);
for(int z=count-1;z>=0;z--){
printf("%d",a[z]);}
break;
case 7: // 实现十进制转换16进制
printf("please input the number: ");
scanf("%ld",&n);
while(n!=0){ re = n%16;
if( re>9 ){ a[i++] = (char)(re - 10) + 'a';
}else{ a[i++] = (char)re + '0'; }
n = n>>4; }
a[i--] = '\0';
for(j=0;j<((i+1)>>1);j++){b = a[i-j]; a[i-j] = a[j]; a[j] = b;}
printf("%s\n",a);
break;
case 0:
printf("exit Calculator");
break;
default:
printf("invalid number ");
break;
}
} while (select);
return 0;
}