Programming Question #: operator determination
Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )
Note: Total time limit: 1000ms memory limit: 65536kB
Describe
After two integers a and b are calculated, the result is C. Expressed as: a? b = C, where,? may be addition +, subtraction-, multiplication *, divisible/or residual%. Determine the operator based on the value of the input a,b,c. If an operation is established, the corresponding operator is output, and if no operation is established, the error is output.
For example:
Input:
3,4,5
Output:
Error
If you enter:
3,4,3
The output:
%
Input
Values of a B and C take care of inline input, with a comma interval
Output
One of the five operators or an error
Sample input
6,7,13
Sample output
+
1#include <stdio.h>2#include <iostream>3 4 intMain ()5 {6 intA, B, C;7scanf"%d,%d,%d",&a,&b,&c);8 if(a+b==c)9 {Tenprintf"+"); One}Else if(a-b==c) A { -printf"-"); -}Else if(a*b==c) { theprintf"*"); -}Else if(b!=0&&a/b==c) - { -printf"/"); +}Else if(b!=0&& a%b==c) - { +printf"%c",'%'); A}Else { atprintf"Error"); - } - return 0; -}
POJ C Programming Problem # # #: operator determination