Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Advertisements

Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
CSCI 130 Advanced Program Control Chapter 8. Program Controls so far for loop while loop do…while loop.
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Fundamentals of Algorithms MCS - 2 Lecture # 4
Understanding Loops Using C Language Week 15 Mr.Omer Salih.
CS201 - Repetition loops.
Some loop programs 1: Read in 10 integers and output their sum
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Algorithm & Flow Charts
A step-by-step procedure for solving a problem in a finite number of steps.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
1. Agenda for loop Short-handed notation How to use break and continue 2.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
CS 162 Intro to Programming II Insertion Sort 1. Assume the initial sequence a[0] a[1] … a[k] is already sorted k = 0 when the algorithm starts Insert.
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 04 loops 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
PGT C Programming1 Week 4 – Repetition Structures / Loops.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
Program Program is a collection of instructions that will perform some task.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Algorithm & Flow Charts Decision Making and Looping
The following statements are for y = -1; if ( x ) if ( x>0 ) y = 1; else y = 0; A. y= -1 x0 B. y= 0 x0 C. y= 1 x
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
The Repetition control structure using while loop.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
Control Structures (Repetition structure) Jump Statements
Problem Solving & Computer Programming
WHILE, DO-WHILE AND FOR LOOPS
Algorithm & Flow Charts Week 1
Flowchart Symbols Terminal Process Input/ Output Decision
REPETITION CONTROL STRUCTURE
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
PROGRAM CONTROL STRUCTURE
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Quick Test What do you mean by pre-test and post-test loops in C?
CS1010 Programming Methodology
C# and the .NET Framework
Iteration statement while do-while
Programming Fundamentals
Control Structures Lecture 7.
CS1100 Computational Engineering
Introduction to Programming
CS1100 Computational Engineering
Conditional Construct
Structured Program
Chapter 6 Decision Making and Looping
Loops in C.
Repetition Control Structure
Week 6 CPS125.
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Department of Computer Science
More Loops Topics Counter-Controlled (Definite) Repetition
Presentation transcript:

Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS

Definition Loops are used to represent repetitive statements In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop therefore consists of two segments, 1. body of the loop 2. control statements.

Structure of Loops Entry Controlled Loop Exit Controlled Loop Exit

Types of Loops 1. For Loop 2. While Loop 3. Do-While Loop Before studying Loops, let us study how to write algorithm and flowchart of loop based programs

Algorithm examples –loops Problem1: To print first n Numbers Problem2: To print sum of first “n” Numbers Problem3: To print all even numbers up to “n” Study all the above Problems Well.

Problem: To print first n Numbers Step 1: Start Step 2: Read n,i=1 Step 3: Is i<=n then goto step 4 else goto step 6 Step 4: Print i Step 5: i=i+1, goto step 3 Step 6: Stop

Problem: To print sum of first “n” Numbers Step 1: Start Step 2: Read n,i=1,sum=0 Step 3: Is i<n then goto step 4 else goto step 6 Step 4: sum=sum+i; Step 5: i=i+1, goto step 3 Step 6: Print sum Step 7: Stop

Problem: To print all even numbers up to “n” Step 1: Start Step 2: Read n, i=1 Step 3: Is ( i<=n) then goto step 4 else goto step 6 Step 4: Is (i%2=0) then print “i” Step 5: i=i+1, goto step 3 Step 6: Stop

Flowchart examples –loops Problem1: To print first n Numbers Problem2: To print sum of first “n” Numbers Problem3: To print all even numbers up to “n” Study all the above Problems Well.

Problem: To print first n Numbers Start Read N, I=1 Stop Is I< =N Yes No Output: N= Output: N= I=I+1 d=n%0 Print I

Problem: To print first n Numbers Start Read N, I=1 n=n/10 Stop Is I<=N Yes No Output: N= Output: N= sum+=d Print sum

Problem: To print first n Numbers Start Int a[5], n=n/10 Stop Is n!=0 Yes No Output: N= Output: N= sum+=d d=n%10 Print sum

Problem: To print sum of first “n” Numbers Start Read n, i=1,sum=0 i=i+1 Stop Is i<=n Yes No Print sum Sum=sum+i

Problem: To print all even numbers up to “n” Start Read n, i=1,sum=0 Stop Is i<=n Yes No Is i%2=0 Print i Yes i=i+1 No Output: N= Output: N=

Structure of While, Do While Loop

Structure of for loop

C Programs examples –loops Problem1: To print first n Numbers Let us study how to write above program using while, Do-while and For loops

Problem: To print first n Numbers #include void main() { int n, i=1; printf(“Enter n”); scanf(“%d”,&n); while(i<=n) { printf(“%d”, i); i++; } Program Using while loop

Problem: To print first n Numbers #include void main() { int n, i=1; printf(“Enter n”); scanf(“%d”,&n); do { printf(“%d”, i); i++; }while(i<=n); } Program Using do-while loop

Problem: To print first n Numbers #include void main() { int n,i; printf("Enter n:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { printf("%d\n",i); } } Program Using for loop

Practice Programs Print first N numbers Print sum of first N Numbers Print all even numbers upto N Print all odd numbers upto N Print sum of even numbers up to N Print sum of odd numbers up to N Print sum of even and sum of odd numbers up to N

Assignment 3 1. C program to print sum of even numbers upto “n” 2. C program to print sum of odd numbers upto “n” 3. C program to average of first n numbers

Start Read N elements of array i<=n Yes No Read N, Int a[5],esum=0,osum=0 i=1 a[i]%2=0 esum+=a[i] osum+=a[i] No i=i+1 Yes Print even sum, Print odd sum Stop