Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C.

Slides:



Advertisements
Similar presentations
Exercise (1).
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Al-Karma Language School Computer Department Prep. 3.
Chapter 6: Algorithmic Problem Solving 1 Chapter 6 Algorithmic Problem Solving.
CS1010 Programming Methodology
Overview. What is Computer Programming? It is the process of planning a sequence of steps (called instructions) for a computer to follow. 2 STEP 1 STEP.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
CMPUT101 Introduction to Computing(c) Yngvi Bjornsson & Jia You1 Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem.
D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath.
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
1 Lab Session-IV CSIT121 Fall 2000 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercises Lab Exercise for Demo.
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.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Computer Science 1620 Programming & Problem Solving.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Complexity (Running Time)
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
BBS Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms.
Chapter 1 Pseudocode & Flowcharts
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
Real World Applications: Statistical Measures Problem (page 95-98) Read a series of floating-point numbers from the standard input, and print a statistical.
Programming Training Main Points: - Problems with repetitions. - Discuss some important algorithms.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
How to start Visual Studio 2008 or 2010 (command-line program)
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Basic Control Structures
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
EXERCISES for ALGORITHMS WRITING
Basic problem solving CSC 111.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.
Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
INTRODUCTION TO PROGRAMMING. Program Development Life Cycle The program development life cycle is a model that describes the stages involved in a program.
The Hashemite University Computer Engineering Department
Slide 1 Lesson 35 Testing for Divisibility WO.17Use long division to determine if one number is divisible by another. WO.23Use divisibility rules to determine.
1 Lab Session-IV CSIT121 Spring 2002 Some Questions Scope of Variables Top Down Design Problem The Solution Lab Exercises Lab Exercise for Demo.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
WHAT IS THIS? Clue…it’s a drink SIMPLE SEQUENCE CONTROL STRUCTURE Introduction A computer is an extremely powerful, fast machine. In less than a second,
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Recursively Enumerable and Recursive Languages
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
CS1010 Programming Methodology
Unit 3: ALGORITHMS AND FLOWCHARTS
Algorithm Discovery and Design
Algorithm Discovery and Design
CS150 Introduction to Computer Science 1
Divide and Conquer Algorithms Part I
CS150 Introduction to Computer Science 1
Examples Example Problems, their Algorithms, and their C Source Code.
EPSII 59:006 Spring 2004.
CHAPTER 6 Testing and Debugging.
Lecture 6 - Recursion.
Presentation transcript:

Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C

Introduction to Problem SolvingS1.2.2 Bina © 1998 Liran & Ofir Problem Solving l Describe the steps that the computer should take in order to solve the problem should take in order to solve the problem n How to get the computer solve a problem? Algorithm

Introduction to Problem SolvingS1.2.3 Bina © 1998 Liran & Ofir Steps of Problem Solving 1. Understand the problem to be solved Analysis 2. Devise a solution to the problem Algorithm Design

Introduction to Problem SolvingS1.2.4 Bina © 1998 Liran & Ofir Steps of Problem Solving 3. Verify that the solution is correct Desk check 4. Describe the solution using a programming language language Programming

Introduction to Problem SolvingS1.2.5 Bina © 1998 Liran & Ofir Steps of Problem Solving 5. Verify that the program does state the solution correctly solution correctly Testing

Introduction to Problem SolvingS1.2.6 Bina © 1998 Liran & Ofir Understand the problem n What is the problem? n What are the inputs? n What are the outputs? n What are examples of input output relationships?

Introduction to Problem SolvingS1.2.7 Bina © 1998 Liran & Ofir Understand the problem n What is the problem? l Compute the average of 3 numbers

Introduction to Problem SolvingS1.2.8 Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: 3 values

Introduction to Problem SolvingS1.2.9 Bina © 1998 Liran & Ofir Understand the problem n What are the outputs l Output: The average of the input values

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: Output: 3.2

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: Output: 3.86

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Step 1. Accept the input values Computer

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Step 1. Accept the input values Step 2. Compute the average Computer Compute the Average

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Compute the Average Step 3. Display the average Step 1. Accept the input values Step 2. Compute the average

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2 Step 3. Display the average Step 1. Accept the input values Step 2. Compute the average Step 2.1. Add up the three values Step 2.2. Divide the result by 3

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2.1 Step 2.1. Add up the three values l Let “A” denote the first value l Let “B” denote the second value l Let “C” denote the third value l Let “Sum” denote the sum of “A”, “B”, and “C” Sum = A + B + C;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2.2 Step 2.1. Divide the result by 3 l Let “Average” denote the average of “A”, “B” and “C” Average = Sum / 3.0;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct A Step 1. Accept the input values, A, B, C 3.9 B 4.1 C 1.3 Step 3. Display the average Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; C B A

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Sum Verify that the solution is correct Step 3. Display the average 9.3 Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; C B A

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average Sum C B A

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average Sum C B A Average is 3.1

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; float A,B,C; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; float A,B,C; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Sum = A + B + C; float A,B,C; float Sum; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average = Sum / 3.0; Sum = A + B + C; float A,B,C; float Sum; float Average; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; printf(“%f”,Average); Average = Sum / 3.0; Sum = A + B + C; float A,B,C; float Sum; float Average; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the program does state the solution correctly n Enter the program n Compile n Run n Compare the output to expected output

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir SelectionSelection n Facilitates the selection of one of a number of various alternatives based on a condition. If the door is open Then Enter the room Else Knock at the door

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem l Accept two integer values and decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number smaller number n What is the problem?

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: 2 Integer Values

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem l Output: Yes n What are the outputs If the larger number is divisible by the second number l Output: No If the larger number is not divisible by the second number

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 4 2 Output: Yes

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 12 Output: Yes

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 7 Output: No

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number? smaller number? Step 1. Accept the input values Computer

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number? smaller number? Compute the result Step 1. Accept the input values Step 2. Compute and display the result the result

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2. Step 2. Compute and display the result l Let “A” denote the first value l Let “B” denote the second value l Let “Larger” denote the larger value l Let “Smaller” denote the smaller value

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2. Step 2.1. If Larger is divisible by Smaller Then print “Yes” Then print “Yes” Otherwise, Larger is not divisible Otherwise, Larger is not divisible by Smaller and print “No” by Smaller and print “No” Step 2. Compute and display the result

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir A Verify that the solution is correct 4 B 2 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Output: Yes Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir A Verify that the solution is correct 3 B 12 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Output: Yes Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir A Verify that the solution is correct 3 B 7 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A Step 2. Compute and display the result Output: No Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” int a,b; scanf(“%d”,&a); scanf(“%d”,&b);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” if (a > b) { largest = a; largest = a; smallest = b; smallest = b; } else { largest = b; largest = b; smallest = a; smallest = a;} int a,b; int largest,smallest scanf(“%d”,&a); scanf(“%d”,&b);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” If (largest % smallest == 0) printf(“Yes”); printf(“Yes”); else printf(“No”); printf(“No”); if (a > b) { largest = a; largest = a; smallest = b; smallest = b; } else { largest = b; largest = b; smallest = a; smallest = a;} int a,b; int largest,smallest scanf(“%d”,&a); scanf(“%d”,&b);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir IterationIteration n Facilitates the repeated execution of a segment of the program. l While you are hungry l Buy a sandwich l Eat the sandwich l While you haven’t read the last slide l Read the next slide

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n What is the problem? l Accept an Integer, N as input and print the value of … + N value of … + N

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: one integer value, N

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n What are the outputs l Output: … + N

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 Output: 6

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 4 Output: 10

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to print the value of … + N Step 1. Accept the input value Step 2. Compute the sum Step 3. Display the sum

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2 Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.1. Count = 1; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step Count = Count +1;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum N 3 Step 2.1. Sum = 0; Step 2.1. Count = 1; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step Count = Count +1;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 1

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 1

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Sum 0 1 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 1

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir 1 Sum 1 2 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 1 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 2

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Sum 1 3 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 2

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir 2 Sum 3 3 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 3

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Sum 3 6 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 3

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir 3 Sum 6 4 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 6 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 4

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Sum 0 6 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step Sum = Sum + Count; Step 2.1. Count = 1; Step Count = Count +1; Count 4 6

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Step Sum = Sum + Count; Describe the solution using a programming language Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; int n; scanf(“%d”,&n);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language int sum; int n; sum = 0; Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; scanf(“%d”,&n);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language count = 1; Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; int count; int n; int sum; sum = 0; scanf(“%d”,&n);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language While (count <= n){ } Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language sum = sum+count; sum = sum+count; Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; While (count <= n){ } count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; sum = sum+count; sum = sum+count; } While (count <= n){ count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n); count = count +1;

Introduction to Problem SolvingS Bina © 1998 Liran & Ofir Describe the solution using a programming language printf(“%d”,sum); Step Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps N times Step 2.1. Count = 1; Step Count = Count +1; sum = sum+count; sum = sum+count; count = count +1; count = count +1; While (count <= n){ } count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);