linux简易计算器
时间: 2023-11-21 15:58:37 浏览: 87
简易计算器
以下是一个简单的Linux计算器的实现方法:
```c
#include <stdio.h>
#include <math.h>
int main() {
char operator;
double num1, num2, result;
printf("请输入运算符 (+, -, *, /, %%, ^):");
scanf("%c", &operator);
printf("请输入两个数字:\n");
scanf("%lf %lf", &num1, &num2);
switch(operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
case '%':
result = fmod(num1, num2);
break;
case '^':
result = pow(num1, num2);
break;
default:
printf("错误!运算符无效。");
}
printf("结果为:%.2lf", result);
return 0;
}
```
阅读全文