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-else statement
  • if-else if-else statement
  • switch statement

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:

Decision Making Statements in C

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,

C Programming if-else statement

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,

C Programming nested if-else statement

if-else if-else statement

The if-else if-else statement is useful when the 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,

C Programming else-if statement

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 the syntax:

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,

C Programming switch statement

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 Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

Operators in C Programming
Loops in C Programming
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment