Unit 2 The Decision Control Structure LECTURE - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Unit 2 The Decision Control Structure LECTURE

Description:

Title: Unit 2 The Decision Control Structure LECTURE 13 Author: p k mishra Last modified by: p k mishra Created Date – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 9
Provided by: pkm5
Category:

less

Transcript and Presenter's Notes

Title: Unit 2 The Decision Control Structure LECTURE


1
Unit 2 The Decision Control
Structure LECTURE 13
  • A Program is nothing but the execution of
    sequence of one or more Instructions. On the
    basis of application it is essential.
  • To Alter the flow of a program.
  • Test the logical conditions
  • Control the flow of execution as per the
    selection.
  • These conditions can be placed in the program
    using decision making statements. C Language too
    much be able to perform different sets of action
    depending on the circumstances. The major
    decision making instructions are listed below.
  • The if statement
  • The if else statements
  • The if-else-if ladder statements(nested if)
  • The switch ( ) case statements.

2
Unit 2 The Decision Control
Structure LECTURE 13
  • 1.The if statement- C uses the keyword if to
    execute a set of command lines or one command
    line when the logical condition is true. It has
    only one option. The set of command lines or
    command lines are executed only when the logical
    condition is true.
  • Syntax of if statement
  • if(condition is true) Note No semicolon
  • statements

3
Unit 2 The Decision Control
Structure LECTURE 13
  • Program using if -
  • Q. WAP to check whether the candidate age is gt
    than 17 or not. If yes, display message Eligible
    for voting.
  •  
  • includeltstdio.hgt
  • void main()
  • int age
  • printf( Enter your Age)
  • scanf(d, age)
  • if (agegt17)
  • printf( Eligible For Voting)

4
Unit 2 The Decision Control
Structure LECTURE 13
  • Q. WAP to check two no are equal.
  • includeltstdio.hgt
  • void main()
  • int m,n
  • printf( Enter Two No)
  • scanf(dd, m,n)
  • if (m-n 0)
  • printf( \nTwo No are Equal)
  •  

5
Unit 2 The Decision Control
Structure LECTURE 13
  • 2.The if else statements- The if else
    statements takes care of true as well as false
    condition. It has two blocks, one block is for if
    and it is executed when the condition is true.
    The other block is of else and it is executed
    when the condition is false. The else statement
    cannot be used without if. No multiple else
    statements are allowed with one if.
  • Syntax of if-else statement
  • if(condition is true) Note No semicolon
  • execute the statements
  • else
  • execute the statements

6
Unit 2 The Decision Control
Structure LECTURE 13
  • Programs using if-else -
  • Q. Read the values of a, b, c through the
    keyboard. Add them and after addition check if it
    is in the range of 100 200 or not print
    separate message for each.
  • includeltstdio.hgt
  • void main()
  • int a,b,c,d
  • printf( Enter Three No a b c)
  • scanf(ddd, a,b,c)
  • dabc
  • if (dlt200 dgt100)
  • printf( \nSum is d which is in between 100
    200, d)
  • else
  • printf(\n Sum is d which is out of range, d
    )

7
Unit 2 The Decision Control
Structure LECTURE 13
  • Q. If his basic salary is less then Rs. 1500,
    then HRA 10 of basic salary and DA 90 of
    basic salary. If his salary is either equal to or
    above Rs. 1500 then HRA Rs. 500 and DA 98 of
    salary. Find the Gross Salary.
  • includeltstdio.hgt
  • void main()
  • float bs, gs, da, hra
  • printf( Enter Basic Salary)
  • scanf(f, bs)
  • if (bslt1500)
  • hrabs10/100
  • dabs90/100
  • Else
  • hra500
  • dabs98/100
  • gsbshrada
  • printf(Gross SalaryRs f, gs )

8
Unit 2 The Decision Control
Structure LECTURE 13
  • Thanks
Write a Comment
User Comments (0)
About PowerShow.com