W. Mathematical Expression – Codeforces Problem Solution in C

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/W

//https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/W
//Mathematical Expression Ascii values
#include<stdio.h>
int main() {
    int a,b,c;
    char x,y;
    scanf("%d %c %d %c %d",&a,&x,&b,&y,&c);
    if(x==43){
        if(a+b==c){
            printf("Yes");
        }
        else{
            printf("%d",a+b);
        }
    }
    else if(x==45){
        if(a-b==c){
            printf("Yes");
        }
        else{
            printf("%d",a-b);
        }
    }
    else if(x==42){
        if(a*b==c){
            printf("Yes");
        }
        else{
            printf("%d",a*b);
        }
    }
    return 0;
}

Assiut University Training – Newcomers solution

Leave a Comment