Answers for "c calculator program"

C
1

c calculator program

#include <stdio.h>
int main() {
    char operator;
    double first, second;
    printf("Enter an operator (+, -, *,): ");
    scanf("%c", &operator);
    printf("Enter two operands: ");
    scanf("%lf %lf", &first, &second);

    switch (operator) {
    case '+':
        printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
        break;
    case '-':
        printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
        break;
    case '*':
        printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
        break;
    case '/':
        printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
        break;
        // operator doesn't match any case constant
    default:
        printf("Error! operator is not correct");
    }

    return 0;
}
Posted by: Guest on November-10-2020
0

how to make calculator in c language

#include <stdio.h>
//Simple Calculator
int main() {

        int fno;
        int sno;
        int rst;
       char opr;
       printf ( "Enter First Number: ");
       scanf("%d", &fno);
       printf ("Enter Second Number: ");
       scanf("%d", &sno);
       printf ("Type Operator : ");
       scanf(" %c", &opr);
       rst = fno + sno;
    if (opr == '+')
    
        printf ("%d \n", fno+sno);
    
      else (opr == '-');
        printf ("%d \n", fno-sno);

    if (opr == '*')
    
        printf("%d \n", fno*sno);

      else (opr == '/');
        printf ("%d \n", fno/sno);
}
Posted by: Guest on July-02-2021
0

calculator in c

/*C program to design calculator with basic operations using switch.*/
 
#include <stdio.h>
 
int main()
{
    int num1,num2;
    float result;
    char ch;    //to store operator choice
     
    printf("Enter first number: ");
    scanf("%d",&num1);
    printf("Enter second number: ");
    scanf("%d",&num2);
     
    printf("Choose operation to perform (+,-,*,/,%): ");
    scanf(" %c",&ch);
     
    result=0;
    switch(ch)    
    {
        case '+':
            result=num1+num2;
            break;
             
        case '-':
            result=num1-num2;
            break;
         
        case '*':
            result=num1*num2;
            break;
             
        case '/':
            result=(float)num1/(float)num2;
            break;
             
        case '%':
            result=num1%num2;
            break;
        default:
            printf("Invalid operation.\n");
    }
 
    printf("Result: %d %c %d = %f\n",num1,ch,num2,result);
    return 0;
}
Posted by: Guest on July-01-2021

Code answers related to "C"

Browse Popular Code Answers by Language