-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path109_if_else_condition.c
42 lines (24 loc) · 1.09 KB
/
109_if_else_condition.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
#include<stdio.h>
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num < 0)
{
printf("%d is a negative number\n", num);
}
else if (num == 0)
{
printf("%d is zero\n", num);
}
else
{
printf("%d is a positive number\n", num);
}
// This code prompts the user to enter a number and checks if it's negative, zero, or positive using if else statements.
// Note the use of the logical operators < and == inside the conditions. The first condition is true if the input number is less than zero, the second condition is true if it's equal to zero, and the third condition is true if it's greater than zero.
// Also, note how we use printf to print different messages depending on the input number. If it's negative, we print "is a negative number". If it's zero, we print "is zero". If it's positive, we print "is a positive number".
// This is just a simple example, but if else statements are very useful in programming, as they allow you to execute different blocks of code based on different conditions.
return 0;
}