#include <stdio.h>
void print()
{
printf("******************计算器*******************\n");
printf("*****1.ADD 2.SUB*******\n");
printf("*****3.DIV 4.MUL*******\n");
printf("*****5.XOR 6.NOT*******\n");
printf("********** 0.exit ************\n");
printf("******************************************\n");
}
void Add(int* x,int* y)
{
int z = *x + *y;
printf("Add= %d\n",z);
}
void Sub(int* x, int* y)
{
int z = *x - *y;
printf("Sub= %d\n", z);
}
void Mul(int* x, int* y)
{
int z = *x * *y;
printf("Mul= %d\n", z);
}
void Div(int* x, int* y)
{
int z = *x / *y;
printf("Div= %d\n", z);
}
void Xor(int* x, int* y)
{
int z = *x ^ *y;
printf("Xor= %d\n", z);
}
void Not(int* x, int* y)
{
int z = *x; ~ *y;
printf("Not= %d\n", z);
}
int x, y;
int main()
{
print();
int input = 0;
while (1)
{
printf("请输入你要进行的计算\n");
scanf("%d", &input);
switch (input)
{
case 1:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Add(&x,&y);
break;
case 2:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Sub(&x, &y);
break;
case 3:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Div(&x, &y);
break;
case 4:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Mul(&x, &y);
break;
case 5:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Xor(&x, &y);
break;
case 6:
printf("请输入两个数\n");
scanf("%d%d", &x, &y);
Not(&x, &y);
break;
case 0:
printf("退出计算器\n");
break;
default:
printf("输入错误,请重新输入\n");
break;
}
if (input == 0)
{
break;
}
}
return 0;
}
标签:case,函数,int,scanf,计算器,break,printf,void
From: https://blog.51cto.com/u_16425777/8861701