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

Calculator

This document contains a C program that implements a simple calculator. It prompts the user to enter an operator and two operands, then performs the corresponding arithmetic operation based on the operator provided. The program handles addition, subtraction, multiplication, and division, and displays an error message for invalid operators.

Uploaded by

Tobz
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)
19 views1 page

Calculator

This document contains a C program that implements a simple calculator. It prompts the user to enter an operator and two operands, then performs the corresponding arithmetic operation based on the operator provided. The program handles addition, subtraction, multiplication, and division, and displays an error message for invalid operators.

Uploaded by

Tobz
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>
//Ola-Daniel Daniel .O.
//Information And Communication Engineering
//19CK025995
//Calculator

int main()
{
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);

switch (op) {
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;
}

You might also like