0% found this document useful (0 votes)
13 views1 page

Comprog (Sulian0, Mike Lowin C.) - Calculator

The document contains code for a C program that performs basic arithmetic operations like addition, subtraction, multiplication and division on two double numbers input by the user. The program uses a switch statement to evaluate the operator and perform the corresponding arithmetic operation, printing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Comprog (Sulian0, Mike Lowin C.) - Calculator

The document contains code for a C program that performs basic arithmetic operations like addition, subtraction, multiplication and division on two double numbers input by the user. The program uses a switch statement to evaluate the operator and perform the corresponding arithmetic operation, printing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main(){
char op;
double first, second;
printf("Input the Operator (+, -, *, /): ");
scanf(" %c", &op);

printf("Enter the two numbers (Note: Do Not Put an integer between the numbers
(Ex. 20 30): ");
scanf("%lf %lf", &first, &second);

switch (op)
{
case '+':
printf("%.2lf + %.2lf = %.2lf",first,second,(first+second));
break;
case '-':
printf(".2%lf - %.2lf = %.2lf",first,second,(first-second));
break;
case '*':
printf(".2%lf * %.2lf = %.2lf",first,second,(first*second));
break;
case '/':
if (second != 0.0)
printf(".2%lf / %.2lf = %.2lf",first,second,(first/second));
else
printf("Divide by Zero Situation");
break;
default:
printf("Invalid");
}

return 0;
}

You might also like