Fundamentals of C programming

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

More on Algorithms and Problem Solving
ALGORITHMS AND FLOWCHARTS
Algorithms An algorithm is a finite sequence of instructions, logic, an explicit step-by-step procedure for solving a problem. Specific algorithms sometimes.
PROBLEM SOLVING TECHNIQUES
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Prof. B. I. Khodanpur HOD – Dept. of CSE R. V. College of Engineering
ALGORITHMS AND FLOWCHARTS
Fundamentals of Algorithms MCS - 2 Lecture # 4
ITEC113 Algorithms and Programming Techniques
Chapter 3 Planning Your Solution
The Program Design Phases
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOWCHARTS
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Software Life Cycle What Requirements Gathering, Problem definition
Algorithm & Flow Charts
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
ALGORITHM List of instructions for carrying out some process step by step. A sequence of instructions which has a clear meaning and can performed with.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Program Planning and Design Important stages before actual program is written.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
Problem, Problem Solving, Algorithm & Flow Charts –Part 1 Presented By Manesh T Course:101 CS 101CS Manesh T1.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Introduction to Flowcharts
Program Program is a collection of instructions that will perform some task.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
 Problem Analysis  Coding  Debugging  Testing.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Problem Solving Concepts
Unit 3: ALGORITHMS AND FLOWCHARTS
Problem , Problem Solving, Algorithm & Flow Charts –Part 1
Chapter 2- Visual Basic Schneider
ALGORITHMS AND FLOWCHARTS
FLOWCHARTS.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Algorithms and Flowcharts
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Algorithm Algorithm is a step-by-step procedure or formula or set of instruction for solving a problem Its written in English language or natural language.
Introduction to Computer Programming
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Introduction to Programming
Basic Concepts of Algorithm
Presentation transcript:

Fundamentals of C programming - Ompal Singh Sharda University,Gr.Noida

Sharda University,Gr.Noida Topics Algorithm Pseudo code Flow Chart Sharda University,Gr.Noida

Planning of Computer Programming- In today’s world a computer is used to solve various types of problems because it takes very less time as compared to a human being.   1. Analyze the given problem 2. Divide the process used to solve the problem in a series of elementary task. 3. Formulate the algorithm to solve the problem. Now in other words we say that “program must be planned before they are written”.

ALGORITHMS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language

Sharda University,Gr.Noida Algorithm The Term Algorithm refers to the logic of a program. It is a step-by-step description of a solution to the given problem. When sequence of instructions are executed in the specified format and sequence the desired result are obtained. Definition:- A format or set of steps for solving a particular problem is called as algorithm. It has clear starting and stopping point. With specific step by step instructions in each line. Sharda University,Gr.Noida

Characteristics of Algorithm Each instruction should be precise and clear. Each instruction should be executed in a finite time. One or more instructions should not be repeated Infinitely. After executing the instructions the desired result are obtained. It range from Simple to the Complex. Sharda University,Gr.Noida

Sharda University,Gr.Noida Process of algorithm An algorithm must express the steps in the solution in a way that will be suitable for computer processing. It Read Value perform a simple procedure and output the required result. After algorithm a Flowchart is prepared and than it is run in the language form in the computer. Sharda University,Gr.Noida

Three constructs

Sharda University,Gr.Noida Algorithm Find area of a rectangle Step 1: Input L,B Step 2: area=L*B Step 3: Print area Step 4: Exit Find the area of a circle Step 1: Input R Step 2: area=3.14*R*R Sharda University,Gr.Noida

Sharda University,Gr.Noida Step 1: Input SP,CP Step 2: if (SP>CP) then p=SP-CP Print p else l=CP-SP Print l endif Step 3:Exit Sharda University,Gr.Noida

Sharda University,Gr.Noida Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif Step 4:Exit Sharda University,Gr.Noida

Sharda University,Gr.Noida Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX ← N1 [N1>N2, N1>N3] else MAX ← N3 [N3>N1>N2] endif if (N2>N3) then MAX ← N2 [N2>N1, N2>N3] MAX ← N3 [N3>N2>N1] Step 3: Print “The largest number is”, MAX Sharda University,Gr.Noida

Sharda University,Gr.Noida Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE > 60) then Print “Ist” elseif (GRADE > 50)and (GRADE <60) then Print “IInd” else Print “Fail” endif Step 4:Exit Sharda University,Gr.Noida

Sharda University,Gr.Noida Step 1: Input the value of N Step 2: Set i=1 Step 3: Repeat step 4 and 5 until i<=N Step 4: Print i Step 5: Set i=i+1 end loop Step 6: Exit Sharda University,Gr.Noida

Sharda University,Gr.Noida Pseudo code First produce a general algorithm (one can use pseudo code) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English. Sharda University,Gr.Noida

Sharda University,Gr.Noida Pseudocode Pseudocode is an informal description of an algorithm English-like statements that require less precision than a formal programming language. Allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax. A good pseudocode algorithm should be independent of, but easily translated into, any formal programming language. Sharda University,Gr.Noida

Pseudocode Control Structures Sequence control structures Instructions are performed linearly Conditional control structures A choice/selection is made between multiple courses of action Looping/iteration control structures Enables repeating instructions within the algorithm A test condition determines when the repetition ends Sharda University,Gr.Noida

Pseudocode Control Structures Selection and conditional 1. if (condition) then 2. statement 1 3. ... 4. endif • If the (condition) is TRUE then statements between THEN and ENDIF are executed once Sharda University,Gr.Noida

Sharda University,Gr.Noida Two-way decision 1. if (condition) then 2. statement 1 3. ... 4. else 5. statement n+1 6. ... 7. endif • If the (condition) is TRUE then statements between THEN and ELSE are executed once • If the (condition) is FALSE then statements between ELSE and ENDIF are executed once Sharda University,Gr.Noida

Sharda University,Gr.Noida LOOP For Loop– Used to implement statements that needs to be repeated a fixed number of times. 1. for i ←1 to n 2. Statement 1 3. ... 4. next i • i is the index or counter that starts with some value and increases by one every time through the loop until it reaches the given maximum value Sharda University,Gr.Noida

Sharda University,Gr.Noida Repeat …until Repeat Loop– Used to implement statements that needs to be repeated until the condition becomes TRUE. 1. repeat 2. Statement 1 3. ... 4. until (condition) Sharda University,Gr.Noida

Sharda University,Gr.Noida While LOOP While Loop– Used to implement statements that needs to be repeated while the condition is TRUE. 1. while (condition) 2. Statement 1 3. ... 4. endwhile Sharda University,Gr.Noida

Sharda University,Gr.Noida Advantages Converting a pseudo code to a programming language is easier than converting a flow chart to programming language. It is easier to modify the pseudo code of a program logic when program modification is necessary. Required less time and effort than flow chart. Sharda University,Gr.Noida

Sharda University,Gr.Noida Limitations A graphical representation of program logic is not available. There are no standard rules to follow in using pseudo code. It is very difficult for beginners. Sharda University,Gr.Noida

Sharda University,Gr.Noida Pseudocode Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks. Sharda University,Gr.Noida

Sharda University,Gr.Noida Pseudocode Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS” Sharda University,Gr.Noida

Sharda University,Gr.Noida Flowchart A Flowchart is a pictorial representation of an algorithm. The First flowchart is made by John Von Newman in 1945. It is a symbolic diagram of operation sequence, dataflow, control flow and processing logic in information processing. The symbol used are simple and easy to learn. It is a very help full tool for programmers and beginners. Sharda University,Gr.Noida

Sharda University,Gr.Noida The Flowchart (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program. (Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart. Sharda University,Gr.Noida

Sharda University,Gr.Noida The Flowchart A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next Sharda University,Gr.Noida

Sharda University,Gr.Noida Purpose of flowchart Provide Communication. Provide an overview. Show all elements and its relationship. Quick method of showing program flow. Check program logic. Facilitate coding. Provide program revision. Provide Program documentation. Sharda University,Gr.Noida

Advantages of flowchart. Communication. Effective analysis. Proper documentation. Efficient coding. Proper debugging. Efficient program maintenance. Easy and clear presentation. Sharda University,Gr.Noida

Limitation of flowchart Complex logic. Drawing is time consuming. Alteration and modification. Redrawn many times. Difficult to draw and remember. Reproduction ( replica ). Technical detail. Sharda University,Gr.Noida

Symbols used in flowchart All symbols are of different shape and size. All have specific meaning and use. The ANSI ( American National Standard Institute) group categories symbols in 3 types basic, specialized and additional symbols. These institution and standardized these basic symbols for use. Sharda University,Gr.Noida

Sharda University,Gr.Noida BASIC SYMBOLS Terminal Symbol = for start and stop. INPUT and OUTPUT = Any function of input and output data. Processing = An arithmetic and data movement instruction. Shows mathematical calculation and logic operations. Sharda University,Gr.Noida

Sharda University,Gr.Noida SYMBOLS Decision = Diamond indicate decision point in the program flow. IT may have 2 way branch or 3 way also. Flow Lines = A Straight line between two boxes shows the path of logic flow in the program. An arrow head on the top of the line shows the direction of the flow, data from top to bottom and left to right. Connectors = 2 small circles are used to connect separated portions of a flowchart without drawing lines between the parts. One connector indicated where the flow breaks off the other where it resumes. Sharda University,Gr.Noida

Sharda University,Gr.Noida Flowchart Symbols Basic Sharda University,Gr.Noida

Flowcharts for three constructs

Sharda University,Gr.Noida Example START Input M1,M2,M3,M4 GRADE(M1+M2+M3+M4)/4 IS GRADE<50 PRINT “FAIL” STOP Y N Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print “FAIL” else Print “PASS” endif PRINT “PASS” Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudocode: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM) Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 2 Algorithm Step 1: Input Lft Step 2: Lcm  Lft x 30 Step 3: Print Lcm Flowchart START Input Lft Lcm  Lft x 30 Print Lcm STOP Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 3 Algorithm Step 1: Input W,L Step 2: A  L x W Step 3: Print A START Input W, L A  L x W Print A STOP Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 4 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 4 Pseudocode: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2 Sharda University,Gr.Noida

Sharda University,Gr.Noida Example 4 Algorithm: Step 1: Input a, b, c Step 2: d  sqrt ( ) Step 3: x1  (–b + d) / (2 x a) Step 4: x2  (–b – d) / (2 x a) Step 5: Print x1, x2 START Input a, b, c d  sqrt(b x b – 4 x a x c) Print x1 ,x2 STOP x1 (–b + d) / (2 x a) X2  (–b – d) / (2 x a) Sharda University,Gr.Noida

Example 5

Sharda University,Gr.Noida Thank you Ompal Singh Sharda University,Gr.Noida

Sharda University,Gr.Noida