Suppose I want to add all the even integers from 1 to 100 (inclusive)

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Exercise (1).
Registers and Ranges. Register – Compared to a Calculator If there are only 9 digits available on display how long can the number displayed be? ANS: 9.
Discovering Divisibility Rules.
CS150 Introduction to Computer Science 1
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
JavaScript with Input & Output Step 1: Use tags JavaScript Template.
Special Sum The First N Integers. 9/9/2013 Sum of 1st N Integers 2 Sum of the First n Natural Numbers Consider Summation Notation ∑ k=1 n k =
EXAMPLE 2 Adding Integers Find the sum 12 + – – 4 = 8 – Different signs, so subtract |4| from | 12|. – Use sign of number with greater absolute.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
More While Loop Examples CS303E: Elements of Computers and Programming.
Practice with Lists and Strings CS303E: Elements of Computers and Programming.
Find each difference. Adding and Subtracting Integers COURSE 2 LESSON 1-7 b. –7 – 2 a. 5 – (–3) 5 – (–3) = 5 + (3)Add the opposite of –3, which is 3. =
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
Count and add list of numbers From user input and from file.
Math – What is a Function? 1. 2 input output function.
Positive and Negative numbers. Negative numbers A positive or negative whole number, including zero, is called an integer. For example, –3 is an integer.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Exercise 1 Introduction to C# CIS Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
Exercise 3 Example> Write a C function that implements /* input : integer value n output : */ int f ( int n ) { int i, sum=0; for (i=1;i
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
The Accumulator Pattern Summing: Add up (“accumulate”), e.g. 1 2 plus 2 2 plus 3 2 plus … plus Variation: Form a product (instead of sum), e.g.
Mean, Median, and Mode Lesson 7-1. Mean The mean of a set of data is the average. Add up all of the data. Divide the sum by the number of data items you.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 9 For Loops.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
Input, Output and Variables GCSE Computer Science – Python.
Multiplication
while Repetition Structure
Data Types and Conversions, Input from the Keyboard
1 Introduction to Algebra: Integers.
Vectors - Adding two angle magnitude vectors Contents:
Printing Lines of Asterisks
Multiplication
Introduction to C++ October 2, 2017.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Using Rules to Subtract Integers
Rules of Integers.
PROGRAMMING Program Development.
Chapter 8 The Loops By: Mr. Baha Hanene.
56% Enter your text here This is a sample text. Enter your text here
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
G7 programing language Teacher / Shamsa Hassan Alhassouni.
February 2, February 2,
Objective - To add and subtract decimals.
Examples Example Problems, their Algorithms, and their C Source Code.
15-110: Principles of Computing

Algorithms for Integer Arithmetic
Representing Integers
Python Basics with Jupyter Notebook
Adding and Subtracting Integers
YOUR text YOUR text YOUR text YOUR text
CLICK TO ADD TITLE IN HERE
X values y values. x values y values Domain Range.
C.2.10 Sample Questions.
C.2.8 Sample Questions.
Errors.
C.2.8 Sample Questions.
2 4 −4 −2 −5 −3 −
WE VALUE… SO WE… #WorldValuesDay enter value
PLEASE ADD YOUR TITLE HERE.

单击此处添加文字标题 单击此处添加副标题.
WE VALUE… SO WE… #WorldValuesDay enter value
Presentation transcript:

Suppose I want to add all the even integers from 1 to 100 (inclusive) Suppose I want to add all the even integers from 1 to 100 (inclusive). Which of the following code samples will do it? sum = 0 for i in range(2,99,2): sum = sum + i print sum sum = 0 for i in range(2,100,2): sum = sum + i print sum sum = 0 for i in range(2,101,2): sum = sum + i print sum

What is the output? Enter the number. Here’s some code: sum = 0 for i in range(3): for j in range(5): sum = sum + 1 print sum

What is the output? Enter the number. Here’s some code: sum = 0 for i in range(3): for j in range(5): sum = sum + j print sum