C Programming + Tutorials in C for Beginners

C Branching Statements

Home  »  C Programming  »  C Branching Statements


    In the term software or computer programming, it has a set of instruction (in simple or complex form) called program. These instructions are also called statements, which occurs sequentially or in either conditional way or in the iterative way. To handle such types of statements some flow controls required. These flow controls are called Control Statements

    In other words, the control statements are used to control the cursor in a program according to the condition or according to the requirement in a loop. There are mainly three types of control statements or flow controls. These are illustrated as below:

Contents

Branching Statement

  1. if statement
    1. Simple if statement
    2. if-else statement
    3. nested if statement
    4. else-if or ladder if or multi-condition if statement
  2. switch statement
  3. conditional operator statement

Branching



if statement

     The if statement is a powerful decision making statement which can handle a single condition or group of statements. These have either true or false action....
    When only one condition occurs in a statement, then simple if statement is used having one block.









if-else statement

     This statement also has a single condition with two different blocks. One is true block and other is false block...



Output is as :
Enter the Number
4
This is Even Number









nested if statement

     When an if statement occurs within another if statement, then such type of is called nested if statement.



Output is as :
Enter the three Ages of Ram,Sham and Ajay
14
17
19
Ram is Youngest







Ladder if or else if statement

     When in a complex problem number of condition arise in a sequence, then we can use Ladder-if or else if statement to solve the problem in a simple manner.

The marks obtained by a student in 5 different subjects are input through the keyboard. The student gets a division as per the following rules:

=> Percentage above or equal to 60 - First Division
=> Percentage between 50 and 59 - Second Division
=> Percentage between 40 and 49 - Third Division
=> Percentage less than 40 - Fail





Method-1



Method-2









switch statement

    When number of conditions (multiple conditions) occurs in a problem and it is very difficult to solve such type of complex problem with the help of ladder if statement, then there is need of such type of statement which should have different alternatives or different cases to solve the problem in simple and easy way. For this purpose switch statement is used. .



Output is as :
Enter the Choice from Four Days...
S = Sunday
M = Monday
T = Tuesday
H = Thursday

S
Sunday

Conditional Control Statement

     This statement is based on conditional operator. This statement solves the problem's condition in a single line and is a fast executable operation. For this purpose we can take combination of ? and :




<< Previous Topic
Next Topic >>



Previous
Next Post »

11 comments

Click here for comments
Unknown
admin
1 August 2018 at 20:38 ×

Simple and easy to students

Reply
avatar
suman
admin
25 August 2018 at 09:08 ×

thank you for sharing nice article in your blog
visit
web programming tutorial
welookups

Reply
avatar
Karan Joshi
admin
7 September 2018 at 08:51 ×

great content with simple language

Reply
avatar
Unknown
admin
13 May 2019 at 06:29 ×

Plz flow charts bhi kr dijiye include

Reply
avatar
Kavya meda
admin
30 May 2019 at 09:04 ×

Easily Understandable

Reply
avatar
Unknown
admin
31 July 2019 at 09:38 ×

pls put programs should be short

Reply
avatar
suman
admin
4 August 2019 at 05:41 ×

nice article for beginners.thank you.
c tutorial
java tutorial

Reply
avatar
Unknown
admin
15 September 2019 at 02:02 ×

Thx for ur great help ☺️🤗

Reply
avatar
Unknown
admin
5 January 2022 at 07:28 ×

Sir ho ske to ise hindi me bhi explain kriyega please

Reply
avatar
Thanks for your comment