Flow Chart. The diagrammatic representation shows a solution to a given problem.

Similar documents
Assignment: 1. (Unit-1 Flowchart and Algorithm)

SHARDA UNIVERSITY SCHOOL OF ENGINEERING & TECHNOLOGY Mid Term Examination, (Odd Term, ) SOLUTION

Computers Programming Course 6. Iulian Năstac

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Operators and Expressions:

Questions Bank. 14) State any four advantages of using flow-chart

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Chapter 2: Overview of C. Problem Solving & Program Design in C

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

Prepared by: Shraddha Modi

Functions. Arash Rafiey. September 26, 2017

Decision Making -Branching. Class Incharge: S. Sasirekha

Control Structure: Loop

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

3/13/2012. ESc101: Introduction to Computers and Programming Languages

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Question Bank (SPA SEM II)

1. The keyword main in C language is used for

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

C library = Header files + Reserved words + main method

C: How to Program. Week /Mar/05

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Tribhuvan University Institute of Science and Technology 2065

Computer System and programming in C

Lecture 02 C FUNDAMENTALS

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

CCE RR REVISED & UN-REVISED KARNATAKA SECONDARY EDUCATION EXAMINATION BOARD, MALLESWARAM, BANGALORE G È.G È.G È..

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

EC 413 Computer Organization

Relational operators (1)

LAB 5: REPETITION STRUCTURE(LOOP)

Functions. Systems Programming Concepts

Chapter 2 - Introduction to C Programming

Arithmetic Expressions in C

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

MODULE 2: Branching and Looping

PROGRAMMING IN C AND C++:

Week 2 Introduction to Computer and Algorithm (Part 2)

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Lab 2: Structured Program Development in C

ET156 Introduction to C Programming

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Lab ACN : C++ Programming Exercises

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Lecture 3. More About C

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

COMP 208 Computers in Engineering

Conditional Statement

Decision making with if Statement : - Control Statements. Introduction: -

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

Dept. of CSE, IIT KGP

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Flowchart & Algorithm

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

Programming and Data Structure

Full file at C How to Program, 6/e Multiple Choice Test Bank

15 FUNCTIONS IN C 15.1 INTRODUCTION

Decision Making. if Statement. Decision Making

Chapter 3 Structured Program Development

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

ALGORITHM 2-1 Solution for Exercise 4

Expression and Operator

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Multiple Choice Questions ( 1 mark)

LAB 5: REPETITION STRUCTURE(LOOP)

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Programming for Engineers Introduction to C

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

Code No: R Set No. 1

1. General Computer Questions

Computers in Engineering. Moving From Fortran to C Michael A. Hawker

ANSI C Programming Simple Programs

Unit 3. Operators. School of Science and Technology INTRODUCTION

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

BİL200 TUTORIAL-EXERCISES Objective:

Lesson 3 Introduction to Programming in C

Computers in Engineering. Moving From Fortran to C Part 2 Michael A. Hawker

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

BRANCHING if-else statements

For instance, we can declare an array of five ints like this: int numbers[5];

CS1100 Introduction to Programming

Computers in Engineering COMP 208. Roots of a Quadratic in C 10/25/2007. Moving From Fortran to C Part 2 Michael A. Hawker

Basic Assignment and Arithmetic Operators

3. Types of Algorithmic and Program Instructions

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

C Programs: Simple Statements and Expressions

Transcription:

low Charts

low Chart A flowchart is a type of diagram that represents an algorithm or process, showing the steps as various symbols, and their order by connecting them with arrows. he diagrammatic representation shows a solution to a given problem. 2

A Quick Glance at low Chart Var a, b, c Input a, b, c b 2 b 4ac b, 2a 2 b 4ac 2a 3

Why low Chart? low charts are useful in analyzing, designing, documenting or managing a process or program. he process is more understandable for humans. Potential errors/mistakes/exceptions are minimized. You can easily organize large problems. Well-established flow charts can be easily translated to computer programs (here, to "C" language). 4

low Chart Components Arrows: Shows flow of control and end symbols: Represents the start and end of a process Generic processing steps: start stop x x + 1 Represents generic computations (e.g., add 1 to x) Prepare conditional (declare variables) : var x Shows operations which have no effect other than preparing a value for a subsequent conditional or decision step Declare variables for the flow chart 5

low Chart Components Input/Output: read x Data input/output given by a user Document: print x or hello Report data so that humans can read them Decision (or Conditional) : x > 1 true false Make a decision on which branch the flow goes to. Commonly asks yes/no or true/false question 6

How to Make low Chart Construct it from the primary basic elements Expand it step by step est whether all the cases are handled est again whether correct outputs are obtained. 7

How to Make low Chart: Examples Given a, b and c, find the solutions of ax 2 +bx+c = 0 Var a, b, c Input a, b, c b 2 b 4ac b, 2a 2 b 4ac 2a 8

How to Make low Chart: Examples Given a, b and c, find the solutions of ax 2 +bx+c = 0 Var a, b, c Input a, b, c a = 0 -c/b b 2 b 4ac b, 2a 2 b 4ac 2a 9

How to Make low Chart: Examples Given a, b and c, find the solutions of ax 2 +bx+c = 0 Var a, b, c Input a, b, c c = 0 b = 0 a = 0 Nothing all real numbers -c/b b 2 b 4ac b, 2a 2 b 4ac 2a 10

How to Make low Chart: Examples Given a, b and c, find the solutions of ax 2 +bx+c = 0 Var a, b, c Input a, b, c c = 0 b = 0 a = 0 b 2 4ac 0 Nothing All real numbers -c/b b 2 b 4ac b, 2a 2 b 4ac 2a No real numbers 11

Example 1 Read a number and print it Var x Input x Print x 12

Example 2 Read a number and print "Even" if it is even or "Odd" if it is odd Var x Input x "Even" x is even? "Odd" 13

Example 3 Add all integers between 1 and 100 Var i, sum i <- 1 sum <- 0 i 100 sum <- sum + i sum i <- i + 1 14

Example 4 Add all even integers between 1 and 100 Var i, sum i <- 1, sum <- 0 i 100 i is even? sum <- sum + i sum i <- i + 1 15

Example 5 ind the maximum among 3 numbers Var a, b, c Input a, b, c a > c a > b b > c a c b c 16

Example 6 Sort 3 numbers Var a, b, c Input a, b, c a>b b>c a>c a>c b>c a, b, c a, c, b c, a, b b, a, c b, c, a c, b, a 17

Example 7 ind the largest n such that 1+2+ +n<1000 Var n, sum n <- 1, sum <- 0 sum <- sum + n sum < 1000 n <- n + 1 n-1 18

Example 8 n-th term of ibonacci sequence a 1 =1, a 2 =1, a n =a n-1 +a n-2 a <- 1, b <-1, k <- 3 Var a, b, c, k, n k n c Input n c <- a + b n = 1 or 2 a <- b 1 b <- c k <- k + 1 19

Example 9 Given n, 1+2+3+...+n Var n, a, k Input n k <- 1, a <-0 k n a <- a + k k <- k + 1 a 20

Example 10 1+(1+2)+(1+2+3)+...+(1+...+10) Var n, a, sum sum <- 0 n 10 sum <- sum + a n <- n + 1 sum a <- a + n 21

low Chart and C

Basic Structure of C program In the beginning, there are a couple of #include <..> Include standard library (routines) for basic functionalities All programs have one main() function which is an entry of each program void main(void) statements Most of the statements should be terminated with ; Case-sensitive E.g., Printf and printf are different #include <stdio.h> void main() int x; scanf( "%d", &x ); printf( "%d\n", x*x ); return; statements 23

1. Conversion of Input/Output Arrows : Nothing necessary to the next statement Otherwise, convert it to goto label; /End : : no conversion : convert to return; a a+k k k+1 a=a+k; k=k+1; Declaration of variables: Convert to int i, j, k; Var i, j, k int is a variable type (abbreviation of integer ). he variable name is made of alphanumeric characters, but should start with alphabet. 24

1. Conversion of Input/Output Input: scanf( "%d", &x); scanf( "%d%d", &x, &y); Output: Input x Print x Input x, y Printing numbers: printf( "%d\n", x); Print x, y printf( "%d %d\n", x, y); Printing characters: printf( "abc\n" ); Print "abc" "abc" 25

Example 1 Read a number and print it Var x Input x Print x #include <stdio.h> main() int x; scanf( "%d", &x ); printf( "%d\n", x ); return; 26

2. Conversion of Conditional (1) ype 1 ype 2 Condit ion A B if(condition) A; B; C; D; Condi tion C D A B if(condition) A; B; else C; D; C E E; D 27

2. Conversion of Conditional (2) if statement condition C D E A B if( condition ) A; B; else C; D; E; hings to do if the condition is true hings to do if the condition is false hings to do after the if statement 28

2. Conversion of Conditional (3) Example B D condi tion1 condi tion2 C E A if(condition1 ) if(condition2 ) C; else B; D; else A; E; 29

Example 2 Read a number and print "Yes" if it is 2 or "No" #include <stdio.h> main() Var x int x; scanf( "%d", &x ); "Yes" Input x x == 2 "No" if( x == 2 ) printf( "Yes\n" ); else printf( "No\n" ); return; 30

Example 3 ind the maximum among 3 numbers #include <stdio.h> main() Var a,b,c int a, b, c; a a > c Input a,b,c a > b b > c c b c if(a > b ) if(a > c ) printf( "%d\n", a ); else printf( "%d\n", c ); else if( b > c ) printf( "%d\n", b ); else printf( "%d\n", c ); return; 31

2. Conversion of Conditional (4) Comparison symbols: Comparison operators for conditional statements Meaning C Operators Examples = == a == 2!= a!= 3 < < a < 3 > > a > 4 <= a <= 5 >= a >= 3 not!!(a < 3) and && (3 < a) && (a < 5) or (a < 3) ( 5 < a) 3 < a < 5? 32

2. Conversion of Conditional (5) Examples: try on your own a is greater than 3 and less than 5 a is greater than 3 and not less than 5 negation of A is greater than 3 and not less than 5 a is equal to or greater than 3 a is less than 3 or greater than 5 a is not equal to 3 a is not greater than 3 33

3. Conversion of Processing Processing symbol : Processing symbol can contain many statements. Convert <- to = (assignment operator) a a + 1 a=a+1; Arithmetic operators meaning C operators examples + (addition) + a + 2 (subtraction) a 3 (multiplication) * a * 3 / (division) / a / 4 Modulo (remainder) % a % 5 34

4. Conversion of Loop ype 3 Repeat the statements while the condition is true condi tion A B C while( condition) A; B; C; 35

Example 6 Add all integers between 1 and 100 Var i, sum i <- 1 #include <stdio.h> #include <math.h> main() int i, sum; i = 1; sum = 0; sum <- 0 i 100 sum <- sum + i i <- i + 1 sum while( i <= 100 ) sum = sum + i; i = i + 1; printf( "%d", sum ); return; 36

Example 7 Add all even integers between 1 and 100 #include <stdio.h> #include <math.h> Var i, sum main() int i, sum; i <- 1, sum <- 0 i = 0; sum = 0; i 100 i is even? sum <- sum + i sum while( i <= 100 ) if( i % 2 == 0 ) sum = sum + i; i = i + 1; printf( "%d", sum ); i <- i + 1 return; 37

Example 8 #include <stdio.h> #include <math.h> n-th term of ibonacci sequence a 1 =1, a 2 =1, a n =a n-1 +a n-2 main() int a, b, c, k, n; scanf( "%d", &n ); Var a, b, c, k, n Input n n = 1 or 2 1 a<-1, b<-1, k<-3 k n c <- a + b a <- b b <- c c if( (n == 1) (n == 2) ) printf( "%d", 1 ); else a = 1; b = 1; k = 3; while( k <= n ) c = a + b; a = b; b = c; k = k + 1; k <- k + 1 printf( "%d", c ); return; 38

Summary lowchart A diagram to represent a process a computer needs to perform to solve a problem Easy to understand for human Easy to be converted to programming languages including C Draw a flowchart before coding a program Lab introduction In the room #400212 39