C语言,简单计算机代码
#include
#include
#define p 3.14
int jia(int a, int b) //加
{
return a + b;
}
int jian(int a, int b) // 减
{
return a - b;
}
int cheng(int a, int b) //乘
{
return a * b;
}
int chu(int a, int b) //除
{
return a / b;
}
void menu()
{
printf(" @@@ 菜单 @@@\n");
printf("***** 1.加减 2.十进制转换 3.三角函数 *****\n");
}
int main()
{
while(1)
{
int i=0,n,a[200];
int r;
int c;
int tallax=1;
menu();
scanf("%d", &tallax);
switch (tallax) //
{
case 1:
printf("***** 1.加 2.减 3.乘 4.除 *****\n");
int input=1;
int x = 0;
int y = 0;
int ret = 0;
scanf("%d", &input);
if (input >= 1 && input <= 4)
{
printf("输入两个数:(1 3)\n");
scanf("%d%d", &x, &y);
}
else
printf("输入错误");
switch (input)
{
case 1:
ret = jia(x, y);
printf("%d+%d = %d\n",x,y,ret);
break;
case 2:
ret = jian(x, y);
printf("%d-%d = %d\n",x,y,ret);
break;
case 3:
ret = cheng(x, y);
printf("%d*%d = %d\n",x,y,ret);
break;
case 4:
ret = chu(x, y);
printf("%d/%d = %d\n",x,y,ret);
break;
case 0:
printf("退出\n");
break;
}
break;
case 2:
printf("******十进制转换成2/8/16进制******\n\n");
printf("十进制转换成 ? 进制\n");
scanf("%d",&r);
printf("输入一个十进制数\n") ;
scanf("%d",&n);
c=0;
if(n<0)
{
c=1;
n=-n;
}
while(n>0)
{
a[i++]=n%r;