A Small Step Toward Calculators

  A Small Step Toward Calculators

Alice has a string of the form x+y or x-y. Here,  and  are single-digit nonnegative integers. Her task is to perform the addition or subtraction accordingly and print the result.
As a newbie programmer, Alice is struggling to finish the task. Can you help her?
Input Format
In a single line, you will be given the string.
Constraints
  • The string contains exactly  characters of the form x+y or x-y.
Output Format
In a single line, print the result of the operation.
Sample Input 0
0+1
Sample Output 0
1
Sample Input 1
0-3
Sample Output 1
-3

Code:

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main() {
    int a,b;
    char c;
    scanf("%d%c%d",&a,&c,&b);
    switch(c)
    {
        case '-':printf("%d",a-b);
            break;
        case '+':printf("%d",a+b);
            break;
    }
    return 0;
}

Please do comment If u have any Queries!

Add a Comment

Your email address will not be published. Required fields are marked *