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.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Control Structures.
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Unit 2 The if-else-if LECTURE – 14
1 CSC103: Introduction to Computer and Programming Lecture No 8.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
C++ for Engineers and Scientists Third Edition
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
1 CSC103: Introduction to Computer and Programming Lecture No 7.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Chapter 4: Control Structures SELECTION STATEMENTS.
If Statements If statements: allow the computer to make a decision Syntax: if (some condition) { then do this; } else { then do that; } no semicolons on.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
Lecture #7 CONTROL STRUCTURE & FLOW CHARTS
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Agenda Basic Logic Purpose if statement if / else statement
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Decisions, Decisions, Decisions Conditional Statements In Java.
Control statements Mostafa Abdallah
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 5.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
Program Control: Selection Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
BY ILTAF MEHDI(MCS,MCSE, CCNA) 1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI(MCS,MCSE, CCNA) 2 Programming Fundamentals Chapter.
THE DECISIONS CONTROL STRUCTURE! CHAPTER 2. Transfer of control statement: o The statement of computer program are executed one after the other in the.
Branching statements.
If/Else Statements.
EKT120 COMPUTER PROGRAMMING
INC 161 , CPE 100 Computer Programming
Chapter 4: Control Structures I
Decisions Chapter 4.
Lecture 7: Repeating a Known Number of Times
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Condition Statements.
Control Structures.
Chapter 4: Control Structures I
IF if (condition) { Process… }
1) C program development 2) Selection structure
Relational, Logical, and Equality Operators
Conditionals.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Branching statements Kingdom of Saudi Arabia
Presentation transcript:

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. 1Basic of Computer & 'C' programming

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; 2Basic of Computer & 'C' programming

Program using if :- Q. WAP to check whether the candidate age is > than 17 or not. If yes, display message “Eligible for voting”. #include void main() { int age; printf(“ Enter your Age”); scanf(“%d”, &age); if (age>17) printf(“ Eligible For Voting”); } 3Basic of Computer & 'C' programming

Q. WAP to check two no are equal. #include void main() { int m,n; printf(“ Enter Two No”); scanf(“%d%d”, &m,&n); if (m-n= =0) printf(“ \nTwo No are Equal”); } 4Basic of Computer & 'C' programming

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; 5Basic of Computer & 'C' programming

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. #include void main() { int a,b,c,d; printf(“ Enter Three No a b c”); scanf(“%d%d%d”, &a,&b,&c); d=a+b+c; if (d =100) printf(“ \nSum is %d which is in between 100 &200”, d); else printf(“\n Sum is %d which is out of range”, d ); } 6Basic of Computer & 'C' programming

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 then HRA= Rs. 500 and DA= 98% of salary. Find the Gross Salary. #include void main() { float bs, gs, da, hra; printf(“ Enter Basic Salary”); scanf(“%f”, &bs); if (bs<1500) { hra=bs*10/100; da=bs*90/100; } Else { hra=500; da=bs*98/100; } gs=bs+hra+da; printf(“Gross Salary=Rs %f”, gs ); } 7Basic of Computer & 'C' programming

Thanks 8Basic of Computer & 'C' programming