Home » , » Decision Making Statements in C

Decision Making Statements in C

 Decision Making Statements in C

Decision-making statements in C language are the same as in other programming languages such as C++, Java, etc. Decision-making is needed when you want a set of instructions to be executed in a condition and other sets of instructions in another condition.


The following are the decision-making statements in C,


if  statement

If the condition is true, the statement gets executed. If the condition is false, it does nothing.


Syntax

The following is the syntax for the if statement in C language,



The following syntax is for multiple statements,



The following is an example showing the usage of the if statement in C language.



The following is the output, wherein the if statement executes since the value of i is more than 5:




if-else statement

If the condition is true, then a set of statements is executed. If the condition is false, another set of statements gets executed.


Syntax

The following is the syntax for the if-else statements in C language,



The following is an example showing the usage of the if-else statement in C language, 



Here’s the output,






You can also work on nested if-else. Let us see how we can do it for the preceding example,



The following is the output, showing what value gets displayed while using nested if-else,





else-if statement

The else-if statement is useful when if-statement has more than one condition.

Syntax

The following is the syntax for the else-if statements in C languages,



The following is an example showing the usage of else-if statement in C languages:



The following is the output, displaying the result for values less than 50,





Switch Statement

Use the switch statement, if you want to take a decision from more than one choice. For example, grades A, B, C, D, E, etc based on the marks of students.

The following is an example showing the usage of the switch statement in C language,




The following is the output, displaying the result for 75 marks,





In this lesson, we learned how to work with Decision Making Statements in C Programming. We saw how to implement if, if-else, else-if, and switch statements in C.

If you liked the tutorial, spread the word and share the link and our website LANGUAGE CODING with others.

0 comments:

Post a Comment

Popular Posts

GENRES

 
Copyright ©

latest code update bloggingskillBest coding website in india

Created By Sora Templates | Distributed By Gooyaabi Templates