Print the following triangle, using nested loops

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

LOOPS Loops are lines of code that can be run more than one time. Each time is called an iteration and in for loops there is also an index that is changing.
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.
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 2 Algorithm Analysis.
Case study 1: Calculate the approximation of Pi
Week 5 - Friday.  What did we talk about last time?  Repetition  while loops.
Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
Repetition. Examples When is repetition necessary/useful?
Chapter 2: Algorithm Analysis Application of Big-Oh to program analysis Running Time Calculations Lydia Sinapova, Simpson College Mark Allen Weiss: Data.
Query Execution :Nested-Loop Joins Rohit Deshmukh ID 120 CS-257 Rohit Deshmukh ID 120 CS-257.
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
COMPSCI 101 Principles of Programming Lecture 27 - Using the Canvas widget to draw rows and columns of shapes.
Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms.
1.6 Loops academy.zariba.com 1. Lecture Content 1.While loops 2.Do-While loops 3.For loops 4.Foreach loops 5.Loop operators – break, continue 6.Nested.
Iteration: WHILE Loop Damian Gordon. WHILE Loop Consider the problem of searching for an entry in a phone book with only SELECTION:
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.
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop initialization and updating ■ event and counter controlled.
CSCI-100 Introduction to Computing
Chapter 9 Efficiency of Algorithms. 9.3 Efficiency of Algorithms.
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
Computer Science: A Structured Programming Approach Using C1 6-6 Loop Examples This section contains several short examples of loop applications. Each.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Elastic Collisions & Sierpinski Carpet Anakaren Santana.
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.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
DEFINITIONS FOR DR. HALVERSON’S CLASSES. DEFINING TERMS A correctly formed DEFINITION of a term consists of 2 parts  Noun – statement of the basic nature.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Learning Objectives 1. Understand how the Small Basic Turtle operates. 2. Be able to draw geometric patterns using iteration.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Trace Tables In today’s lesson we will look at:
PROGRAM CONTROL STRUCTURE
Stage 11: Artist: Nested Loops
Topics discussed in this section:
ALGORITHMS & FLOWCHARTING II
عناصر المثلثات المتشابهة Parts of Similar Triangles
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
More Nested Loops and Lab 5
Alice in Action with Java
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Count Controlled Loops (Nested)
Module 2 Lesson 3 Over and Over Again
Topics discussed in this section:
Domino algorithm.
INC 161 , CPE 100 Computer Programming
Design and Implementation
مديريت موثر جلسات Running a Meeting that Works
Some Common Issues: Iteration
Computer Science Core Concepts
CS150 Introduction to Computer Science 1
INC 161 , CPE 100 Computer Programming
Project 2 Guidelines.
Loops.
CS149D Elements of Computer Science
Input a number and print its table, using FOR loop.
Problem Input a number and print its table using while loop. In the end print Good Bye only once.
Module 2 Lesson 3 Over and Over Again
The structure of programming
Do it now activity Log onto the computer.
Module 2 Lesson 3 Over and Over Again
Thinking procedurally
Remember Procedures A set of instructions grouped together to carry out a task. Run a procedure by using its name. Procedures can be run/used lots of.
Week 5 - Friday CS 121.
Introduction to Python
Presentation transcript:

Print the following triangle, using nested loops. 1 2 1 2 3 2 3 4 Problem Print the following triangle, using nested loops. 1 2 1 2 3 2 3 4 1 2 3 4 5

Algorithm Dry Run i=1 Step 1:- run the for loop from 1 to 5 with i as iterating value i=2 i=3 i=4 i=5 j=1 j=1,2 j=1,2,3 j=1,2,3,4 j=1,2,3,4,5 Step 2:- run second for loop with j from 1 to i Step 3:- print the value of j 1 1 2 1,2,3 1,2,3,4 1,2,3,4,5 Step 4:- print next line \n \n \n \n \n

Task 19 Print using nested for loops 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Task 20 Print using nested for loops 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Group work Print using nested for loops * * * * * * * * * * * * * * * * * * * * * * * * *