calculator in c

Solutions on MaxInterview for calculator in c by the best coders in the world

showing results for - "calculator in c"
Trey
13 Jul 2020
1#include <stdio.h>
2int main() {
3    char operator;
4    double first, second;
5    printf("Enter an operator (+, -, *,): ");
6    scanf("%c", &operator);
7    printf("Enter two operands: ");
8    scanf("%lf %lf", &first, &second);
9
10    switch (operator) {
11    case '+':
12        printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
13        break;
14    case '-':
15        printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
16        break;
17    case '*':
18        printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
19        break;
20    case '/':
21        printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
22        break;
23        // operator doesn't match any case constant
24    default:
25        printf("Error! operator is not correct");
26    }
27
28    return 0;
29}
Juan Pablo
27 Jan 2018
1#include <stdio.h>
2//Simple Calculator
3int main() {
4
5        int fno;
6        int sno;
7        int rst;
8       char opr;
9       printf ( "Enter First Number: ");
10       scanf("%d", &fno);
11       printf ("Enter Second Number: ");
12       scanf("%d", &sno);
13       printf ("Type Operator : ");
14       scanf(" %c", &opr);
15       rst = fno + sno;
16    if (opr == '+')
17    
18        printf ("%d \n", fno+sno);
19    
20      else (opr == '-');
21        printf ("%d \n", fno-sno);
22
23    if (opr == '*')
24    
25        printf("%d \n", fno*sno);
26
27      else (opr == '/');
28        printf ("%d \n", fno/sno);
29}
30
31
Daniela
03 Jul 2016
1/*C program to design calculator with basic operations using switch.*/
2 
3#include <stdio.h>
4 
5int main()
6{
7    int num1,num2;
8    float result;
9    char ch;    //to store operator choice
10     
11    printf("Enter first number: ");
12    scanf("%d",&num1);
13    printf("Enter second number: ");
14    scanf("%d",&num2);
15     
16    printf("Choose operation to perform (+,-,*,/,%): ");
17    scanf(" %c",&ch);
18     
19    result=0;
20    switch(ch)    
21    {
22        case '+':
23            result=num1+num2;
24            break;
25             
26        case '-':
27            result=num1-num2;
28            break;
29         
30        case '*':
31            result=num1*num2;
32            break;
33             
34        case '/':
35            result=(float)num1/(float)num2;
36            break;
37             
38        case '%':
39            result=num1%num2;
40            break;
41        default:
42            printf("Invalid operation.\n");
43    }
44 
45    printf("Result: %d %c %d = %f\n",num1,ch,num2,result);
46    return 0;
47}
queries leading to this page
simple c calculator programhow to make calculator in c on basiccalculator function in cc programming solverc calculate with 25how to make a simple calculator on ca simple calculator in cwrite a program in c to calculatercalculatore c program in cc meaning calculatorc program for simple calculatorcalculator in ccreate a simple calculator in c programming presenting option for 4 diffrent capwrite a program of calcultor in c languagecreate a calculator in cc clculatorc program calculatorc calculatorc language buave calculatorbasic calculator program in chow to make a calcualtor in ccalculatrice ccalculator c programwrite a simple calculator using if else statement that prompts the user to input two numbers then it will display the menu for addition 2c subtraction 2c multiplication 2c division 2c square of 1st number 2c cube of 1st after any choice it will display the answercalculator program in c using functionscalculator in c using functionscalculator cghow to make calculator in c languagecalc c compilercalculator in c languagec program for calulatorc calculator programc calculadoracalculator with c languagehow to make a calcaulator in cc calculator onlinec programming langugage calculatorcreate a simple calculator using c programc calculatorcreate calc with cc 27 calculatecreate a calculator using switch case in cwhere to find c in calculatorcalculator with chow to use c in calculatorbasic calculator program in c using functionschange calculator in cc calculator with switchwriting calculator in c languagecalculator c codebuild a simple calculator using cbasic calculation program in cbasic calculator in cbasic calculator code ccreate calculator in ccalc c compiler 27how to make a calculator using csimple calculator program in c using functionsc language calculatorc code calculatorcalculator basic program in cwrite a simple calculator program in cc program for calculatorcalculator using function in cc program calculator using functionshow to create a calculator in cc program calculation using functionsbasic calculator using switch case in cc program for a calculatorcalculator on c languagewrite a calculator in cc language calculator codecalcullator in cclass c subnet calculatorcalculator code cof calculation in ca c program to make a calculatorcalculator with c 28 29write an c program that is calculatorconverting calculation in c programmingcode of calculator in ccalculatrice in cbuild a calculator cc code solverc program simple calculatorswitch case in c to add subtract two numberscalculation coding in ccalculator switch statementc program to make a calculatorc make calculatorc simple calculatorc basic calculatorkalkylator c programmingc how to make calculatorcalculator c meaningcalculator syntax for chow to run make an calculatorhow to implement 3d in a calculator in ccalculator csimple calculation in c languagecalculator using switch case in cbasic calculator c programc sample codes for calculatorsimple calculator in cbuilding calculator cwhat is in 25 in programming calculation simple calculator program in ccode for calculator in cbasic c calculator programcalculator code in conline c calculatormaking calculator in chow to use the calculator function in ccalculator c and cec calculator codesimple calculator in c programcalculator c code sourcehow to create a basic calculator in csimple calculator using ccalculator program in ccalculator c programmingmake calculator in c to find add 2csub and powerc code for calculatorcalculator using chow to make calculator in cc 23 calculatorc program to make all betwice operationsc prgorma calculatorsimple calculator ccalculator syntax cc calculatorhow to calculate in cmake calculator with chow to make a calculator in cwhat does c mean in a calculatorsimple calculatopr in cbasic c calculator program in cc calculatricewhat is c in calculatorcalculator c languagehow to create calculator in ccalculator in c