zzulioj 1037: Four arithmetic

Title description
Give you a simple four-arithmetic expression, including two real numbers and an operator, please program to calculate the result . The format of the
input
expression is: s1 op s2, s1 and s2 are two real numbers, op means operation The operator (+,-,*,/) may also be other characters
output.
If the operation matches the method, the value of the expression is output; if the operator is illegal or the divisor is 0 when the division operation is performed, "Wrong input!" is output. In the final result, two decimal places are reserved.
Sample input Copy
1.0 + 1.0
Sample output Copy
2.00
prompt The
divisor is 0, use |s2|<1e-10 (that is, 10 to the power of 10).

#include<stdio.h>
#include<math.h>
int main()
{
    
    
	float s1, s2;
	char op;
	scanf("%f%c%f",&s1,&op,&s2);
	if(op=='+')
	  printf("%.2f\n",s1+s2);
	  else if(op=='-')
	    printf("%.2f\n",s1-s2);
	    else if(op=='*')
	      printf("%.2f\n",s1*s2);
	      else if(op=='/'&&fabs(s2)>=1e-10)
	      printf("%.2f\n",s1/s2);
	    else
	      printf("Wrong input!\n");
	return 0;
 } 

Guess you like

Origin blog.csdn.net/m0_53024529/article/details/112862691