标签:can har \n turn not 重点 exit 增加 else
在例3-9、例3-5的基础上增加对除数是否为零的判断
程序核心——if语句
#include<stdio.h>
int main()
{
double value1,value2;
char op;
printf("Type in an expression:");
scanf("%lf%c%lf",&value1,&op,&value2);
if(op=='+')
printf("=%.2f\n",value1+value2);
else if (op=='-')
printf("=%.2f\n",value1-value2);
else if (op=='*')
printf("=%.2f\n",value1*value2);
else if (op=='/')
if(value2!=0)
printf("=%.2f\n",value1/value2);
else
printf("Divisor can not be 0!\n");
else
printf("Unknown operator\n");
return 0;
}
Type in an expression:9/0
Divisor can not be 0!
--------------------------------
Process exited after 7.105 seconds with return value 0
请按任意键继续. . .
重点:
标签:can har \n turn not 重点 exit 增加 else
原文地址:https://www.cnblogs.com/5236288kai/p/10582604.html