Algorithm & Flow Charts Decision Making and Looping

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,
Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Introduction to Flowcharting
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
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
 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
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
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.
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.
Basic Control Structures
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.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
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.
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.
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
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
Ch 7: JavaScript Control Statements I.
Chapter 2.2 Control Structures (Iteration)
Programming Fundamentals
Control Structures Lecture 7.
CS1100 Computational Engineering
Introduction to Programming
CS1100 Computational Engineering
Conditional Construct
Chapter 6 Decision Making and Looping
Loops in C.
Repetition Control Structure
Faculty of Computer Science & Information System
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, body of the loop control statements.

Structure of Loops Exit Controlled Loop Entry Controlled Loop Exit

Types of Loops For Loop While Loop 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=0 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 Output: N=5 1 2 3 4 5 Start Read N, I=1 Is I< =N No Yes Print I I=I+1 Stop

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

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

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<stdio.h> 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<stdio.h> 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<stdio.h> 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

Tutorial/Model 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 C program to print sum of even numbers upto “n” C program to print sum of odd numbers upto “n” C program to average of first n numbers