INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Do Loop The syntax of DO loop: DO variable = initial_value, final_value[, increment] [statements] END DO Example: PROGRAM LINES ! Illustration of DO-loops.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
DCT 1123 Problem Solving & Algorithms
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
How to start Visual Studio 2008 or 2010 (command-line program)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
For loops, nested loops and scopes Jordi Cortadella Department of Computer Science.
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Nested for loops.
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
For Loop Tips And Tricks
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
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.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
UCT Department of Computer Science Computer Science 1015F Iteration
Lesson #5 Repetition and Loops.
INC 161 , CPE 100 Computer Programming
REPETITION CONTROL STRUCTURE
INC 161 , CPE 100 Computer Programming
C++ Programming: CS150 For.
Lesson #5 Repetition and Loops.
For loops, nested loops and scopes
PROGRAM CONTROL STRUCTURE
CHAPTER 5A Loop Structure
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Lecture 07 More Repetition Richard Gesick.
Chapter 4 Loops Case Studies
Lecture 4B More Repetition Richard Gesick
INC 161 , CPE 100 Computer Programming
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Control Structure Senior Lecturer
Lesson #5 Repetition and Loops.
Intro to Nested Looping
INC 161 , CPE 100 Computer Programming
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
INC 161 , CPE 100 Computer Programming
Count Controlled Loops (Nested)
Intro to Nested Looping
INC 161 , CPE 100 Computer Programming
Chapter 8: More on the Repetition Structure
Intro to Nested Looping
Week 6 CPS125.
CS150 Introduction to Computer Science 1
ECE 103 Engineering Programming Chapter 19 Nested Loops
Intro to Computer Science Loops
INC 161 , CPE 100 Computer Programming
CS150 Introduction to Computer Science 1
Lesson #5 Repetition and Loops.
Intro to Nested Looping
Print the following triangle, using nested loops
Repetition (While Loop) LAB 9
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
GCSE Computing Mini Assignment.
Control Structures.
Visit for more Learning Resources
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 5

Nested Loop Nested loop = loop inside loop Program flow The inner loops must be finished before the outer loop resumes iteration.

Example1 How many rounds? #include <stdio.h> main () { int i,j; for(i=0;i<5;i++) { printf(“Hello\n”); } How many rounds?

Example1 How many rounds? #include <stdio.h> main () { int i,j; for(i=0;i<5;i++) { for(j=0;j<3;j++) { printf(“Hello\n”); } How many rounds?

Inner loop

Example1 How many rounds? #include <stdio.h> main () { int i,j; for(i=0;i<5;i++) { for(j=0;j<3;j++) { printf(“Hello %d %d\n”,i,j); } How many rounds?

Task 1 1 22 333 4444 55555 666666 ***** * ** *** **** ***** ****** Write program to print the following patterns 1 22 333 4444 55555 666666 ***** * ** *** **** ***** ****** Your code can have only 1 asterisk *

Task 2 Write a flowchart / program to calculate the area of a rectangle. Receive 2 integers from the keyboard, width and height. If either width or height is a negative number, the program has to keep asking for a new number until a positive number is entered. Calculate area = width x height Print the area on the screen.