2025-03-06 22:46:33 +08:00

30 lines
858 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
功能编写一个简单计算器程序输入格式为a op b。其中 a和b是
参加运算的两个数op 为运算符,它的取值只能是+、-、*、/。
例:(注意输出格式)
输入3+4
输出3.000000+4.000000=7.000000
--------------------------------------------------------*/
#include<stdio.h>
main()
{
float a,b;
char op;
printf("Please enter a,b and op:");
scanf("%f,%c,%f",&a,&op,&b);
switch(op)
{
/**********Program**********/
case '+':printf("%f+%f=%f\n", a, b, a+b);break;
case '-':printf("%f-%f=%f\n", a, b, a-b);break;
case '*':printf("%f*%f=%f\n", a, b, a*b);break;
/********** End **********/
case '/':if(b!=0)
printf("%f/%f=%f\n",a,b,a/b);
else
printf("error!\n");break;
default:printf("error!\n");break;
}
}