Simulate the work of the simple scanner. Assume that the calculator can only perform addition, subtraction, multiplication, division operations. The calculation numbers and results are integers. The four operators have the same priority and are calculated from left to right.
Input Format:
The input provides a four-digit arithmetic formula in a row with no space and at least one operand. "=" Indicates that the input is complete.
Output Format:
Output the formula calculation result in a row, or if the Division denominator is 0 or there is an illegal operator, the output error message is "error ".
Input example:
1+2*10-10/2=
Output example:
10
# Include <stdio. h>
Int main ()
{
Int X, flag = 0;
Int result;
Char CH = '1 ';
Scanf ("% d", & result );
While (Ch! = '){
Scanf ("% C", & Ch );
If (CH = ')
Break;
Scanf ("% d", & X );
If (CH = '+ '){
Result + = X;
}
Else if (CH = '-'){
Result-= X;
}
Else if (CH = '*'){
Result * = X;
}
Else if (CH = '/'){
If (X! = 0 ){
Result/= X;
}
Else
Flag = 1;
}
Else
Flag = 1;
}
If (FLAG ){
Printf ("error ");
}
Else
Printf ("% d \ n", result );
Return 0;
}
Wood program writing http://www.codeforu.net