C if Statement
#include <stdio.h>
int main() {
int num = 10;
if (num > 0) {
printf("The number is positive.\n");
} else if (num == 0) {
printf("The number is zero.\n");
} else {
printf("The number is negative.\n");
}
return 0;
}
- Include Header File:
#include <stdio.h>
includes the standard input-output library for using functions likeprintf
.Main Function:
int main() {
marks the beginning of the main function, which is the entry point of a C program.Variable Declaration:
int num = 10;
declares an integer variablenum
and initializes it with the value 10.If Statement:
if (num > 0) {
checks if the value ofnum
is greater than 0.Print Statement (If True):
printf("The number is positive.\n");
prints a message to the console if the condition in theif
statement is true.Else If Statement:
} else if (num == 0) {
provides an alternative condition to check if the value ofnum
is equal to 0, in case the first condition is false.Print Statement (Else If True):
printf("The number is zero.\n");
prints a message to the console if the condition in theelse if
statement is true.Else Statement:
} else {
handles the case when both theif
andelse if
conditions are false.Print Statement (Else True):
printf("The number is negative.\n");
prints a message to the console if none of the previous conditions is true.Return Statement:
return 0;
indicates that the program has executed successfully and exits the main function.
Closing Brace:
}
marks the end of the main function.