Exercise (1).

Slides:



Advertisements
Similar presentations
CS 240 Computer Programming 1
Advertisements

Representing an algorithm using Flowcharts
Introduction to Programming
Revision.
PROBLEM SOLVING TECHNIQUES
Al-Karma Language School Computer Department Prep. 3.
Chapter 2: Problem Solving
Algorithms and Problem Solving
CS 240 Computer Programming 1
Chapter 1 Pseudocode & Flowcharts
Fundamentals of Algorithms MCS - 2 Lecture # 4
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.
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.
Developing logic (Examples on algorithm and flowchart)
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Review Algorithm Analysis Problem Solving Space Complexity
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Algorithm & Flowchart.
Chapter 1 Pseudocode & Flowcharts
Introduction to Algorithm – part one Jennifer Elmer Form 3 Computing.
ALGORITHMS AND FLOWCHARTS
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Software Life Cycle What Requirements Gathering, Problem definition
More While Loop Examples CS303E: Elements of Computers and Programming.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
EXERCISES for ALGORITHMS WRITING
Basic problem solving CSC 111.
Chapter 1 Pseudocode & Flowcharts
Count and add list of numbers From user input and from file.
Lecture 2 Examples Pseudo code and flowcharts. Problem 1 Read a number as input and then print if it is even or odd.
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.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
CS2301:Computer Programming 2
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Problem, Problem Solving, Algorithm & Flow Charts –Part 1 Presented By Manesh T Course:101 CS 101CS Manesh T1.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
Program design Program Design Process has 2 phases:
Programming Languages
Problem , Problem Solving, Algorithm & Flow Charts –Part 1
while Repetition Structure
PROGRAM CONTROL STRUCTURE
Computer Programming Flowchart.
Algorithms and Flowcharts
Chapter 4: Control Structures
Lecture 2 Introduction to Programming
Introduction to Algorithm – part 1
Repetition-Counter control Loop
Chapter 1 Pseudocode & Flowcharts
Compound Assignment Operators in C++
PROBLEM SOLVING CSC 111.
Pseudocode & Flowcharts
PROGRAMMING Program Development.
Chapter 1 Pseudocode & Flowcharts
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CHAPTER 4 Iterative Structure.
Repetition (While Loop) LAB 9
Chapter 1 Pseudocode & Flowcharts
REPETITION Why Repetition?
Presentation transcript:

Exercise (1)

Example: Using Pseudo code, Write suitable algorithm: Calculate and print the average temperature, readings for the degrees as the following T1, T2, T3. Input T1, T2, T3 avg= (T1 + T2 + T3)/3 Print avg Input T1, T2, T3 Sum = (T1 + T2 + T3) Avg = sum/3 Print avg

Flow chart Start or Stop Program Input or Output Process, Calculate, Storage Used to express logical operations or operations report (Condition) Arrows determine the direction of the program's progress Connection

Flow chart start Input : stop Sum = T1+T2+T3 Avg = sum/3 Example : Using flow chart, Write suitable algorithm: Calculate and print the average temperature for the following readings T1, T2, T3. start Input T1, T2, T3 Input : T1, T2, T3 Processing : Sum = T1+T2+T3 Avg = sum/3 Output: Sum = T1+T2+T3 Avg = sum/3 Print avg stop

Note: (if X=0 enter value of X again) Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following equation: Y=(X-2)/X Note: (if X=0 enter value of X again) Flow Chart start Input X If X=0 Pseudo code input X process if x=0 Re-enter the new value of x because you can not divide by 0 “ Y=(X-2)/X output Y yes No Y=(X-2)/X Print Y stop

Flow chart Example: start Stop Using flow chart, Write suitable algorithm: Calculate and print the average temperature. Readings as the following T1, T2, T3. IF the average is greater than 15 print the average, else print the weather is cold. start input T1, T2, T3 Sum= T1+T2+T3 Start Input T1,T2,T3 Sum = T1+T2+T3 Avg = sum/3 If avg > 15 then Print avg Else Print “cold” End if end Avg = sum/3 No Yes avg > 15 Print “cold” Print avg Stop

Discuss Write an algorithm using pseudo code and flow chart for the introduction of 3 degrees and find the average temperature and print the "cool air“ if temperature less than 15, Print "moderate air” if temperature between 15 and 25, and print “hot air” if the temperature not verify the previous conditions.

Answer : End Yes No Yes Print cool No Print moderate Print hot If avg<15 Yes No If avg<25 Yes Print cool No Print hot Print moderate End

Using pseudo code and flow chart to write an algorithm to calculate the area and perimeter of ​​a rectangle. Note: the area of ​​the rectangle = length × width. Perimeter = 2*(length+width)

Using pseudo code and flow chart to write an algorithm to calculate and print the area of a right-angled triangle . The base of the triangle = a The height of triangle= b Equation of area= (1/2)*a*b

Write a program using the pseudo code and flow chart to find the area of ​​a circle which radius R print it. Note: The area of ​​a circle is equal to π * R2, where π is a constant value of approximately 3.14. flow chart start Input r π × r × A= r Print A End Input R Process Π = 3.14 A= π × R × R output Print A End Pseudo code π = 3.14

Using the methods (pseudo code and flow chart), we need to find and print the vicinity of the football stadium, and determine whether international (greater than or equal to 600 m) or local (less so), Note: The perimeter of the rectangle is equal to (length + width) × 2 . flow chart C= 2* (L+W) start Input L,W Print International End Start Input L , W C= 2× ( L + W) If c ≥ 600 then Print “ international” Else Print “ local” End if print c End No If C>=600 Yes Print Local

Formulate resolve the matter to find the zakaah and that if you know money saver and you know that zakaah = 0.025 × money saver, provided the account of zakaah money if it exceeds 1000 SR Flow chart start Pseudo code Input money m Process If m>1000 calculate zakaah else do not calculate zakaah zakaah=0.025*money Output print zakaah Input M M>1000 no yes K=M*0.025 Print k stop

Formulate a solution to print the odd numbers from 1 to 49 ? Pseudo code Output: print output from 1 to 49 Input: no input Process: transfer from odd number to odd number no=1 Print no no=no+2 If no>50 then stop else go to step (2) Flow chart start No=1 Print No No=No+2 no No>50 yes stop

Write a program that accept an integer from the user and print it is Positive or Negative number.

Write a program that accept an integer from the user and test the number . If it is positive print Positive, if it is negative print Negative if equal zero print equal zero.

start Use flow chart to write algorithm. Read an integer from the user and test then number . If it is positive print Positive, if it is negative print Negative if equal zero print equal zero. Enter number (n) yes n>0 Print “positive” No yes N<0 Print “negative” No print “equal zero” end