EXERCISES for ALGORITHMS WRITING

Slides:



Advertisements
Similar presentations
Exercise (1).
Advertisements

PERFORMING CALCULATIONS IN SCIENTIFIC NOTATION
CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
Al-Karma Language School Computer Department Prep. 3.
10 PLC Math Instructions. 10 PLC Math Instructions.
Logic and Algorithm. Developing an algorithm To help the initial analysis, the problem should be divided into 3 separate components: 1.Input: a list of.
EXPONENTS ORDER OF OPERATIONS MULTIPLYING / DIVIDING POWER OF A POWER POWER OF A PRODUCT POWER OF A QUOTIENT NEGATIVE EXPONENTS.
Chapter 1 Pseudocode & Flowcharts
Programming is instructing a computer to perform a task for you with the help of a programming language.
Pseudocode algorithms using sequence, selection and repetition
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Addition, Subtraction, Multiplication, and Division of Integers
Developing an Algorithm
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
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.
More While Loop Examples CS303E: Elements of Computers and Programming.
Developing an Algorithm
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
1. Example 1 – Averages 2. Example 2 – Rolling Dice 3. Example 3 – Number Analysis 4. Example 4 - Divisibility ( while ) Additional Examples on for Loops.
Integer Operations Finding a temperature Higher or Lower 5 Examples Adding / Subtracting Integers using a scale Adding / Subtracting Integers by description.
Pseudocode Algorithms Using Sequence, Selection, and Repetition Simple Program Design Third Edition A Step-by-Step Approach 6.
Basic problem solving CSC 111.
OPERATIONS USING FRACTIONS. 1. Add, subtract, multiply and divide fractions with and without a calculator. 2. Convert between equivalent forms of fractions.
Count and add list of numbers From user input and from file.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Cosc175 - Define Problem/Design Solution/Pseudocode/Trace 1 DEFINE THE PROBLEM.
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.
CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
INTRODUCTION TO PROGRAMMING. Program Development Life Cycle The program development life cycle is a model that describes the stages involved in a program.
Flowcharts. Symbol Terminal Symbol: indicates the starting or stopping pointin the logic. Input/Output Symbol: Represents an input or output process in.
Flowcharts Lecture 12.
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.
Addition Multiplication Subtraction Division. 1.If the signs are the same, add the numbers and keep the same sign = = If the.
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.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Unit 1 Rational Numbers Integers.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
Adding, Subtracting, Multiplying, and Dividing Rational Numbers.
Numbers Sets Natural Numbers – Counting numbers. Does not include 0 (example: 1,2,3,4…) Whole Numbers – All Natural numbers and the number zero (example:
PERFORMING CALCULATIONS IN SCIENTIFIC NOTATION ADDITION AND SUBTRACTION.
Introduction to Python Lesson 2a Print and Types.
Interesting Integers – Part Dos
System Calls & Arithmetic
Multiplication
Operations with Integers
while Repetition Structure
PROGRAM CONTROL STRUCTURE
Knowing your math operation terms
Multiplication
Partial Products Algorithm for Multiplication
Multiplying and dividing integers
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Calculate! 3 X ÷ 2 8 ? 19 ?.
More Loops.
Pseudocode algorithms using sequence, selection and repetition
PROGRAMMING Program Development.
Lecture Notes 8/24/04 (part 2)
Section 5.3 The Rational Numbers
Algebra II September 2, 2011.
Review of Integers and Solving Equations
Unit 1: Number System Fluency Vocabulary Created by: Shavonne Burrows
DIRECTED NUMBERS.
COMPUTING.
Introduction to Pseudocode
Building Java Programs
Presentation transcript:

EXERCISES for ALGORITHMS WRITING

THE PROCEDURE: Define the problem in terms of Input, Process, Output Create a solution algorithm using pseudo-code Problem No.1: Add three numbers A program is required to read 3 numbers, add them together and print their total. Inputs: num_1, num_2, num_3 Process: Addition Outputs: Display total of three numbers Algorithm: - Define num_1, num_2,num_3 and total - Read num_1 - Read num_2 - Read num_3

- Add num_1, num_2 and num_3 into total - Display total Problem No.2: Find Average Temperature A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, then calculate & display to the screen the simple average temperature, calculated by: (maximum temperature + minimum temperature) / 2 Inputs: max_temp, min_temp Process: Add the max_temp & min_temp and then divide by 2 Outputs: Display avrg_temp

Algorithm: - Initialize max_temp, min_temp, avrg_temp - Read max_temp - Read min_temp - Add max_temp & min_temp and then divide by 2 into avrg_temp - Display avrg_temp Problem No.3: Display Characters Construct an algorithm that will prompt user to input 3 chars, receive those 3 chars and display them to screen with a message, such as Hello ABC Inputs: chr_1, chr_2, chr_3 Outputs: Display “HELLO” with chr_1, Chr_2, Chr_3

Algorithm: - Initialize chr_1, chr_2, chr_3 - Get chr_1 - Get chr_2 - Get chr_3 - Display chr_1, chr_2, chr_3 with a Hello message Problem No.4: Calculations A program is required to receive two integers from a terminal operator / user, process them and display to the screen their sum, difference, product and quotient Inputs: num_1, num_2 Process: Addition, Subtraction, Multiplication & Division Outputs: Display sum, diff, mul and div

Algorithm: - Initialize num_1, num_2, sum, diff, mul, div - Get num_1 - Get num_2 - Add num_1 & num_2 into sum - Subtract num_1 from num_2 into diff - Multiply num_1 with num_2 into mul - Divide num_1 by num_2 into div - Display sum, diff, mul and div