Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.
Case study 1: Calculate the approximation of Pi
For loops For loops are controlled by a counter variable. for( c =init_value;c
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
CS 112 Intro to Computer Science II Sami Rollins Fall 2006.
1 ICS103 Programming in C Lecture 17: Array of Strings.
Loops. COMP104 Loops / Slide 2 Shortcut Assignment * C++ has a set of operators for applying an operation to a variable and then storing the result back.
Multidimensional Arrays. Example Write a program to keep track of all warmup scores for all students. Need a list of a list of scores Student – score.
Guidelines for working with Microsoft Visual Studio.Net.
Repetition. Examples When is repetition necessary/useful?
Guidelines for working with Microsoft Visual Studio 6.
לולאות 02 יולי יולי יולי 1502 יולי יולי יולי 1502 יולי יולי יולי 15 1 Department of Computer Science-BGU.
1 Agenda - Loops while for for & while Nested Loops do-while Misc. & Questions.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 2: Control Flow.
CHAPTER 5 CONTROL STRUCTURES II (Repetition). In this chapter, you will:  Learn about repetition (looping) control structures  Explore how to construct.
CGS 3460 Program looping n Why we need loop lMake code concise for repetitive processes n When to use loop lRun a block of code repetitively lProcess multiple.
Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Introduction to Computing Lecture 07: Repetition and Loop Statements (Part.
(Ncc is not a C Compiler) 4 조 ( 말년병장 ) 심민조 김호철.
CS1010E Programming Methodology Tutorial 3 Control Structures and Data Files C14,A15,D11,C08,C11,A02.
AE1205 Programming Python Quiz: so how do we generate Numbers 1 to 10? range( ) Numbers 5,10,15,20,25 to 100? range( ) Numbers 20,18,16, to 0? range( )
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
Exam 2 – Nov 18th Room ACIV 008. Project 2 Update  Your code needs to use loops to create the multiplication table. Hint: use nested for loop (Lecture.
Real World Applications: Generating Prime Numbers  Problem Write a program that prints all positive prime integers less than or equal to n. A positive.
do - while  while: Execute the body of the loop at least once
More While Loop Examples CS303E: Elements of Computers and Programming.
1 Flowchart notation and loops Implementation of loops in C –while loops –do-while loops –for loops Auxiliary Statements used inside the loops –break –continue.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Struct 1. Definition: Using struct to define a storage containing different types. For example it can contain int, char, float and array at the same time.
Introduction to Programming Lecture 7: Repeating Statements.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
ICS103: Programming in C Searching, Sorting, 2D Arrays Muhamed F. Mudawar.
Program Looping Why we need loops in our code –Make code concise for repetitive processes When to use loops –Run a block of code repetitively –Process.
Computer programming Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character.
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
H1-1 University of Washington Computer Programming I Lecture 9: Iteration © 2000 UW CSE.
For Loop Lecture No 8. Definition In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for.
Midterm 2 Review. Stars and why we use nested loops  Matrix problems (stars)  Other problems involving multiple dimensions  Loops within a process.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
2-D Arrays Declaration & Initialization. Declaration You can think of 2D arrays as a matrix rows and columns: – a 4x3 matrix –
Arrays and Matrices. One-Dimensional Arrays An array is an indexed data structure All variables stored in an array are of the same data type An element.
Escape sequence Certain characters, preceded by a backslash ( \ ), are known as escape sequences They are used to display certain characters, or as display.
L AB 4 July 5th. F OR LOOP Exercise 1: Find two ways of “Summing all 1, 2, and 3 digit prime numbers.” Use for loop Hint: isprime, primes.
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.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Python - Iteration A FOR loop is ideal if we know how many times we want to repeat. Try this code: for loopCounter in range(10): print(loopCounter) There.
Programming Loops (continued).
Control Structures (Repetition structure) Jump Statements
Programming application CC213
Multi-dimensional arrays in C
MULTI-DIMENSIONAL ARRAY
Topics discussed in this section:
CS150 Introduction to Computer Science 1
The nested repetition control structures & Continue Statements
Computer Graphics Matrix
Control Structures Lecture 7.
INC 161 , CPE 100 Computer Programming
Lec 7.
Chapter 8 The Loops By: Mr. Baha Hanene.
Counting Loops.
INC 161 , CPE 100 Computer Programming
CS150 Introduction to Computer Science 1
Print the following triangle, using nested loops
Quiz – Lives of Stars.
Iteration Statement for
ICS103: Programming in C Searching, Sorting, 2D Arrays
Programming Fundamental
컴퓨터 프로그래밍 기초 - 13th : 마지막 수업 -
Presentation transcript:

Nested Loops

Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****

Nested Loops //print a rectangle of stars for(i = 0; i < 3; i++) { //print a line of stars }

Nested Loops //print a rectangle of stars for(i = 0; i < 3; i++) { //print a line of stars } //print a line of stars for(i = 0; i < 5; i++) { //print one star printf(“*”); }

Nested Loops //print a rectangle of stars for(i = 0; i < 3; i++) { //print a line of stars for(i = 0; i < 5; i++) //IS THIS OKAY? { //print one star printf(“*”); }

Okay now? //print a rectangle of stars for(i = 0; i < 3; i++) { //print a line of stars for(j = 0; j < 5; j++) { //print one star printf(“*”); }

Okay now? //print a rectangle of stars for(i = 0; i < 3; i++) { //print a line of stars for(j = 0; j < 5; j++) { //print one star printf(“*”); } printf(“\n”); }

Problem Design a program which prompts the user for a number of rows between 0 and 10 and prints the following pattern: ** *** **** …