-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCal.c
65 lines (54 loc) · 1.53 KB
/
Cal.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
// Function to add two numbers
float add(float num1, float num2) {
return num1 + num2;
}
// Function to subtract two numbers
float subtract(float num1, float num2) {
return num1 - num2;
}
// Function to multiply two numbers
float multiply(float num1, float num2) {
return num1 * num2;
}
// Function to divide two numbers
float divide(float num1, float num2) {
if(num2 == 0) {
printf("Error! Division by zero is not allowed.\n");
return 0;
} else {
return num1 / num2;
}
}
int main() {
float num1, num2;
char choice;
printf("Select operation:\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("Enter choice(1/2/3/4): ");
scanf("%c", &choice);
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter second number: ");
scanf("%f", &num2);
switch(choice) {
case '1':
printf("%.2f + %.2f = %.2f\n", num1, num2, add(num1, num2));
break;
case '2':
printf("%.2f - %.2f = %.2f\n", num1, num2, subtract(num1, num2));
break;
case '3':
printf("%.2f * %.2f = %.2f\n", num1, num2, multiply(num1, num2));
break;
case '4':
printf("%.2f / %.2f = %.2f\n", num1, num2, divide(num1, num2));
break;
default:
printf("Invalid choice\n");
}
return 0;
}