-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.c
More file actions
51 lines (43 loc) · 1.15 KB
/
calculator.c
File metadata and controls
51 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
int main() {
char operator;
double num1;
double num2;
double result;
printf("\nEnter an operator (+ - * /): ");
scanf("%c",&operator);
printf("\nEnter number 1: ");
scanf("%lf",&num1);
printf("\nEnter number 2: ");
scanf("%lf",&num2);
switch(operator){
case '+':
result = num1 + num2;
printf("\nResult: %.2lf",result);
break;
case '-':
result = num1 - num2;
printf("\nResult: %.2lf",result);
break;
case '*':
result = num1 * num2;
printf("\nResult: %.2lf",result);
break;
case '/':
result = num1 / num2;
printf("\nResult: %.2lf",result);
break;
default:
printf("\n%c is not a valid operator!",operator);
}
return 0;
}
// Bro Code. (2021.10.7.). C Programming Full Course for free [Video]. YouTube. https://www.youtube.com/watch?v=87SH2Cn0s9A