computer programming unit 1 lecture 4

Download COMPUTER PROGRAMMING UNIT 1 Lecture 4

Post on 19-Aug-2015

25 views

Category:

Engineering

2 download

Embed Size (px)

TRANSCRIPT

  1. 1. COMPUTER PROGRAMMING Lecture 04 Prepared By Mr. V. S. Patil Dept (CSE)/AEC
  2. 2. Unit 1 Problem Solving Syllabus Prepared By Mr. V. S. Patil Dept (CSE)/AEC
  3. 3. 2 1 Understand the logic of algorithm and flow of control. Understand the basics symbols of flowcharts Objectives
  4. 4. Algorithm An algorithm is well defined, finite set of computational instructions that accomplishes a particular task, which may or may not take inputs and produces some value or a set of values as output. In addition all algorithms must satisfy the following criteria: 1.Zero or more quantities are externally supplied: input 2.At least one quantity is produced: output 3.Each instruction is clear and unambiguous: Definiteness 4.The algorithm terminates after a finite number of steps: Finiteness 5.For every input instance, it halts with the correct output:
  5. 5. Conventions used in writing Algorithms Name of Algorithm Introductory Comments Steps Comments
  6. 6. 1 Step 1: [input the three integers] read x, y, z . Step 2: [compute the largest of three numbers] big = x; If(y>big) big=y If(z>big) big=z Step 3: [Write the largest number] Write (big) Step 4: [Finished] exit Algorithm Development Ex- Find maximum of 3 numbers. The variables used are:x, y, z : type integer big : Storing the value of the largest number, type integer 2 3 4
  7. 7. Flowchart Definition:- A flowchart is graphical or pictorial representation of an algorithm. It shows the logic of algorithm and flow of control. Flowchart uses the symbol to represent the specific action and arrow to indicate the flow of control.
  8. 8. Basic symbols of flowchart
  9. 9. Notice there are three types of symbols in this flowchart: rounded rectangles parallelograms a rectangle Each symbol represents a different type of operation. Basic Flowchart Symbols
  10. 10. Sequence Decision Repetition Case Four Flowchart Structures
  11. 11. A series of actions are performed in sequence The pay-calculating example was a sequence flowchart. Ex.- Write an Flowchart for finding the addition of two number. Sequence Structure
  12. 12. Decision Structure One of two possible actions is taken, depending on a condition. A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path. Ex- if (x < y) a = x * 2; else a = x + y;
  13. 13. A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop. A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists. Ex- while (x < y) x++; Repetition Structure x < y? Add 1 to x YES
  14. 14. Case Structure One of several possible actions is taken, depending on the contents of a variable. Ex- Find maximum of 3 nos
  15. 15. Question Bank 1.What is algorithm? 2. Explain Steps involved in algorithm development with suitable example. 3.What is flowchart? 4.Describe the symbol of flowcharts. 5.Draw flowchart for Fibonacci Series.