1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Basic Calculator

Discussion in 'C' started by Anil2447, Aug 28, 2010.

  1. Anil2447

    Anil2447 Guest

    [​IMG]3
    #include
    #include
    int main()
    {
    char operator;
    int num1, num2;
    //char operation[1]={'\0'};
    printf("Enter two numbers and operator to perform calculations!...\n");
    printf("Enter the operator: ");
    scanf("%c",&operator);
    printf("Enter num1: ");
    scanf("%d",&num1);
    printf("Enter num2: ");
    scanf("%d",&num2);

    if (operator=='+')
    {
    printf("Sum is %d\n",num1+num2);
    }
    else if (operator=='-')
    {
    printf("Difference is %d\n",num1-num2);
    }
    else if (operator=='*'){
    printf("Product is %d\n",num1*num2);
    }
    else if(operator=='/'){
    printf("Ratio is %d\n",num1/num2);
    }
    else
    printf("Not given any Operation.");
    }[​IMG]


    Enter two numbers and operator to perform calculations!...

    Enter the operator: +
    Enter num1: 12
    Enter num2: 13
    Sum is 25

    [​IMG]
     

Share This Page