DCT 1123 Problem Solving & Algorithms

Slides:



Advertisements
Similar presentations
Solving Problems with Repetition. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C# program Correctly.
Advertisements

Repetition There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is.
Repetition Control Structures
Program Design Tool. 6 Basic Computer Operations Receive information Put out information Perform arithmetic Assign a value to variable (memory location)
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Repeating Actions While and For Loops
Repetition Control Structure
 2002 Prentice Hall. All rights reserved Control Structures 3 control structures –Sequential structure Built into Python –Selection structure The.
Computer Science 1620 Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Pseudocode and Algorithms
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Repetition Control Structures
Pseudocode.
Pseudocode Algorithms Using Sequence, Selection, and Repetition.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Pseudocode.
There are two additional statements that can be used to control the operation of while loops and for loops: break statements continue statements.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
Combination of Sequence, Selection and Repetition
Pseudocode algorithms using sequence, selection and repetition
Chapter 7 Array processing. Objectives To introduce arrays and the uses of arrays To develop pseudocode algorithms for common operations on arrays To.
Chapter 5 Loops.
Nested LOOPS.
ANALYSIS AND ALGORITHM DESIGN - IV. Repeat statements/looping/counting/iterations It is often necessary to repeat certain parts of a program a number.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Pseudocode Algorithms Using Sequence, Selection, and Repetition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Pseudocode Algorithms Using Sequence, Selection, and Repetition Simple Program Design Third Edition A Step-by-Step Approach 6.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
CS 100 Introduction to Computing Seminar October 7, 2015.
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.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 16 I’m on the Inside; You’re on the Outside.
Flowcharts. Symbol Terminal Symbol: indicates the starting or stopping pointin the logic. Input/Output Symbol: Represents an input or output process in.
1 Programming in C++ Dale/Weems/Headington Chapter 6 Looping.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Selection Using IF THEN ELSE CASE Introducing Loops.
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.
while Repetition Structure
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
PROGRAM CONTROL STRUCTURE
Chapter 5: Control Structure
Ch 7: JavaScript Control Statements I.
Lecture 07 More Repetition Richard Gesick.
Lecture 4B More Repetition Richard Gesick
Repetition and Loop Statements
Control Structure Senior Lecturer
Outline Altering flow of control Boolean expressions
Pseudocode algorithms using sequence, selection and repetition
Iteration: Beyond the Basic PERFORM
3 Control Statements:.
Repetition Control Structure
3.5- The while Statement The while statement has the following syntax:
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Alternate Version of STARTING OUT WITH C++ 4th Edition
A LESSON IN LOOPING What is a loop?
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

DCT 1123 Problem Solving & Algorithms Nested Loop & Combination of selection & repetition

What is nested loop? A nested loop is a loop within a loop, an inner loop within the body of an outer one. The first pass of the outer loop triggers the inner loop, which executes to completion. The second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes. Of course, a break within either the inner or outer loop would interrupt this process.

Syntax while(condition) { { statement(s); } statement(s); // you can put more statements. }

Combination of Selection & Repetition (Sample Problem) Design an algorithm that will prompt for and receive pairs of numbers from an operator at a terminal and display their sum, product & average on the screen. If the calculated sum is over 200, an asterisk is to be displayed beside the sum. The program is terminate when a pair of zero values is entered.

Combination of Selection & Repetition (Sample Problem – Defining Diagram) Input Processing Output Number_1 Prompt for numbers Sum Number_2 Get two numbers Product Calculate sum Average Calculate product ‘*’ Calculate average Display sum, product, average Display ‘*’

Combination of Selection & Repetition (Sample Problem – Solution Algorithms) Set sum = 0 Input number1, number2 WHILE (number1 != 0 AND number2 != 0) sum = number1+number2 product = number1*number2 average = sum / 2 If sum > 200 THEN Display sum, ‘*’, product, average ELSE Display sum, product, average ENDIF ENDDO END

Sample Problem Design an algorithm that will prompt for and receive your age in years and months and calculate and display your age in months. If the calculated months figure is more than 500, three asterisks should also appear beside the month figure. Your program is to continue processing until a sentinel of 999 is entered.

Sample Problem A file student records contains 100 name and their gender (M or F). Design an algorithm that will read through the file and calculate the number of male (M) and female (F) in the records.