// opertion
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int main(void)
{
double number_1 = 0.0;
char operition = 0;
double number_2 = 0.0;
printf("请输入你需要计算的算式:");
scanf("%lf %c %lf",&number_1,&operition,&number_2);
if( (isdigit(number_1)) || (isdigit(number_2)))
{
switch(operition)
{case '+':
printf("=%1f",number_1 + number_2);
break;
case '-':
printf("=%lf",number_1 - number_2);
break;
case '*':
printf("=%lf",number_1 * number_2);
break;
case '/':
if(number_2 == 0)
{
if(number_1 < 0)
printf("=-∞");
else if(number_1 == 0)
printf("你的除数与被除数都为零,无解");
else
printf("=∞");
}
else
printf("%lf",number_1 / number_2);
break;
case '%':
if(number_2 == 0)
printf("\n你的被取模数为零,无解");
else
printf("=%ld",(long)number_1 % (long)number_2);
break;
default:
printf("\n你输入的运算符不正确。");
break;
}
}
else
printf("\n你输入的不是数字。");
getchar();
return 0;
}
慕容森
尚方宝剑之说
相关分类