Example # 1 Draw a flowchart for calculating the area of a room:

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

Exercise (1).
PROBLEM SOLVING TECHNIQUES
Al-Karma Language School Computer Department Prep. 3.
1 Flowchart. 2 Flowchart: It is a diagram consists of symbolic block that represents the algorithm step by step Symbols of flowchart: 1. Terminal (start,
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
ALGORITHMS AND FLOWCHARTS
Fundamentals of Algorithms MCS - 2 Lecture # 4
Unit 2 The if-else-if LECTURE – 14
Basic Programming II. Outline Standard Deviation Function (SD) Complex Guessing Game.
LOOP (Part 2) for while do-while 1. TK1913-C Programming2 TK1913-C Programming 2 Loop : for Loop : for Condition is tested first Loop is controlled by.
Chapter 4 Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
Developing logic (Examples on algorithm and flowchart)
Flowchart Tutorial.
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
Sadegh Aliakbary Sharif University of Technology Spring 2011.
C programming: Variables, Expressions part II. Data Types of Arithmetic Expressions Relational Expressions Logical Expressions Multiple Assignments Compound.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Nested LOOPS.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
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.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
Basic Control Structures
Lecture 2 Examples Pseudo code and flowcharts. Problem 1 Read a number as input and then print if it is even or odd.
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular.
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
SCALE FACTORS AND SIMILARITY Introducing scale factor.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
ACOE161Digital Circuit Design1 Design Of Combinational Logic Circuits.
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
GC101 Introduction to computers and programs
Amalan Kejuruteraan Sem /2014
Unit 3: ALGORITHMS AND FLOWCHARTS
EKT120 COMPUTER PROGRAMMING
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Computer Programming Flowchart.
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Algorithms and Flowcharts
ALGORITHMS & FLOWCHARTING II
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
CS1100 Computational Engineering
PROBLEM SOLVING CSC 111.
Introduction to Programming
ALGORITHMS AND FLOWCHARTS
Topics discussed in this section:
Flowchart.
Introduction to Programming
Aggregate Functions.
Presentation transcript:

Example # 1 Draw a flowchart for calculating the area of a room: In order to calculate the area of the room, we must know firstly the length and the width of the room. Then we calculate the area by multiplying the length by width.

Goal: calculating the area of the room. Input: length and width. Process: area = length * width. Output: area.

C code: don’t worry about it now #include<stdio.h> void main() { int length, width, area; scanf("%d",&lendth); scanf("%d", & width); area = length * width; printf("%d",area); } Flowchart START Input length Input width area = length * width Output area END

The following flowchart is in correct. Can you guess why? START Input length Input width area = length * width END Output area

It is wrong because we cannot calculate the area of the room before knowing the length and width of the room. So, we should input the length and width of the room then calculate area.

Example # 2 Draw a flowchart which reflects the process of deciding whether a student has passed or failed . the course based on the average three exams.

Goal: decide whether the student pass or failed the course. Input: m1, m2, m3 /*m mass mark */ Arithmetic Process: sum = m1 + m2 + m3. average = sum/3. Logical process: is the average greater or equal to 60. Output: passed or failed.

C code:don’t worry about it now #include<stdio.h> void main() { int m1, m2, m3; Int sum, avg; scanf("%d%d%d", &m1,&m2,&m3); sum = m1 + m2 + m3; avg = sum/3; if(avg >=60) { Printf("passed"); } else Printf("faild"); Flowchart START Input m1,m2,m3 sum = m1+m2+m3 avg = sum/3 YES Is avg>=60 NO Output “passed” Output “failed” END

Example # 3 Draw a flowchart which reflects the process of calculating the sum of 5 values: Goal: calculate the sum of 5 values. Input: value Process: adding the values to each other. Output: the sum

C code: don’t worry about it now Flowchart C code: don’t worry about it now #include<stdio.h> void main() { int value, sum, counter; sum = 0; counter = 1; while(counter<=5) { scanf("%d",& value); sum = sum + value; counter = counter + 1; } printf("%d",sum); START Sum = 0 counter = 1 Is Counter<=5 YES NO Input value sum =sum + value counter = counter + 1 Output sum END

Questions? What would happen if the process counter = counter +1 did not exist? What would happen if the process sum =0 did not exist?

Example # 4 Draw a flowchart for finding the maximum value of 10 input values. Goal: finding the maximum value. Input: value Process: comparing to find the maximum value. Output: the maximum value

Flowchart START Input value max = value counter = 1 Is Counter<=10 C code:don’t worry about it now. #include<stdio.h> void main() { int value, max, counter; scanf("%d", & value); max = value; counter = 1; while(counter<=10) { scanf("%d", &value); if(value>max) } counter = counter + 1; printf("The maximum is %d \n ",max); Flowchart START Input value max = value counter = 1 Is Counter<=10 NO YES Input value Is Value>max NO YES max = value counter = counter + 1 Output max END