造梦西游3五重神铁:帮帮忙啊 ,解释哈下面程序,谢谢了,每句都解释哈,

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 12:49:57
#include<stdio.h>
main()
{
float a,b,result;
char op;
scanf("%f%c%f",&a,&op,&b);
switch(op)
{
case'+':
result=a+b;
printf("=%f",result);
break;
case'-':
result=a-b;
printf("=%f",result);
break;
case'*':
result=a*b;
printf("%f",result);
break;
case'/':
if(b==0.0)
printf("error!\n");
result=a/b;
printf("=%f",result);
default:
printf("error due to the illegal input!\n");
break;
}
}

#include<stdio.h>
main()
{
float a,b,result;
char op;
scanf("%f%c%f",&a,&op,&b); // 输入浮点数,字符浮点数,例如 1.5+2.6
switch(op) // 看中间的那个字符是什么符号,是四则运算则执行,并显示
{
case'+': // 加法
result=a+b;
printf("=%f",result);
break;
case'-': // 剑法
result=a-b;
printf("=%f",result);
break;
case'*': // 乘法
result=a*b;
printf("%f",result);
break;
case'/': // 除法
if(b==0.0)
printf("error!\n");
result=a/b;
printf("=%f",result);
default: // 非四则运算符号,提示错误
printf("error due to the illegal input!\n");
break;
}
}

用不着每一句都解释吧
那你也太差了吧