Conditional Statements
In c programming language, decision making is used to specify the order in which statements are executed. In C we use conditional statements to achieve this.
There can be any type of control structures. In our daily life, these kinds of control structures generally achieve or used in our decision-making process.
Control Structures types.
If then If I exercise daily then I will be fit
If else If today rains then I will play FIFA else I will not play FIFA.
else if
In programming, we use a conditional statement to make decisions in the same way as in real life.
If Statement Example
if the expression it true evaluate the statement.
If the expression is true to evaluate statement 1 otherwise evaluate statement 2
Example: Take an input from a user and check number is positive negative or zero.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
In c programming language, decision making is used to specify the order in which statements are executed. In C we use conditional statements to achieve this.
There can be any type of control structures. In our daily life, these kinds of control structures generally achieve or used in our decision-making process.
Control Structures types.
If then If I exercise daily then I will be fit
If else If today rains then I will play FIFA else I will not play FIFA.
else if
In programming, we use a conditional statement to make decisions in the same way as in real life.
If Statement Example
if the expression it true evaluate the statement.
if (expession) {
statement
}
C example. You have given a number, check if the number is positive print Positive on the terminal. if (number > 0) {
printf("Positive");
}
If Else Statement ExampleIf the expression is true to evaluate statement 1 otherwise evaluate statement 2
if (expression) {
statement 1
} else {
statement 2
}
C example. You have given a number, check if the number is positive or not positive and print Positive or Not Positive on the terminal.
if (number > 0) {
printf("Positive");
} else {
printf("Not Positive");
}
Else If Example
if expression 1 is true to evaluate statement 1 if expression 1 is false check expression 2 if it is true to evaluate statement 2 otherwise evaluate statement 3
if (expression 1) {
statement 1
} else if (expession 2) {
statement 2
} else {
statement 3
}
C example. You have given a number, check number is positive, negative or zero and print on terminal positive, negative and zero in respective cases.
if (number > 0) {
printf("Positive");
} else if (number == 0) {
printf("ZERO");
} else {
printf("Negative");
}
#include<stdio.h>
int main() {
int number;
scanf("%d", &number);
if (number > 0) {
printf("Positive");
} else if (number == 0) {
printf("Zero");
} else {
printf("Negative");
}
}
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
You expressed your thoughts in different way and i really enjoyed with your article.
ReplyDeletePython Training in Chennai
Python Training Institute in Chennai
JAVA Training in Chennai
Big data training in chennai
Selenium Training in Chennai
IOS Training in Chennai
Python Training in Annanagar