Identify correct operator. ID:227


An expression E is passed as an input to the program. The expression will contain three numbers A, B and C, one equal symbol and one of the mathematical operators + - * /
But the given mathematical operator is incorrect and hence the expression is not valid. Hence the program must identify the correct operator and print that as the output.


Input Format:
First line will contain the expression E

Output Format:
First line will contain the correct mathematical operator


Sample Input/Output:

Example 1:
Input:
5-4=20

Output:
*

Explanation:
Only 5 multiplied with 4 gives 20. Hence - must be replaced with *.


Example 2:
Input:
999+9=111

Output:
/

Explanation:
Only 999 divided by 9 gives 111. Hence + must be replaced with /.


PROGRAM IN C:

#include<stdio.h>

#include <stdlib.h>


int main()

{

char c1,c2;

int a,b,c;

scanf("%d%c%d%c%d",&a,&c1,&b,&c2,&c);


if(a+b==c)

printf("+");

else if(a-b==c)

printf("-");

else if(a*b==c)

printf("*");

else

printf("/");


 


}

Comments

Popular Posts