-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththree.c
More file actions
34 lines (27 loc) · 779 Bytes
/
three.c
File metadata and controls
34 lines (27 loc) · 779 Bytes
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
#include <stdio.h>
int main() {
float num1, num2;
float addi, subs, div, mul;
// Prompt the user to enter two numbers
printf("Enter the first number: ");
scanf("%f", &num1);
printf("Enter the second number: ");
scanf("%f", &num2);
// Perform calculations
addi = num1 + num2;
subs = num1 - num2;
mul = num1 * num2;
// Check if the second number is zero before performing division
if (num2 != 0) {
div = num1 / num2;
} else {
printf("Error: Division by zero is not allowed.\n");
return 1;
}
// Print the results
printf("addition: %.2f\n", addi);
printf("subtraction: %.2f\n", subs);
printf("multiplication: %.2f\n", mul);
printf("division: %.2f\n", div);
return 0;
}