Computer Programming
Fundamentals
Program Development Life Cycle
Problem Analysis        • Understand the problem
                        • Have multiple solutions
                        • Select a solution
Program Design          • Write an algorithm
                        • Draw a flowchart
                        • Write a pseudo code
Program Development     • Choose a programming language
                        • Write the program
                        • Compile the program and remove syntax errors, if any
                        • Execute the program
                        • Test the program. If the output is incorrect (logical /
                        semantic errors), modify the program to get correct results.
                        • Install the tested program on the user’s computer.
Program Documentation   • Document the program, for later use
and maintenance          • Maintain the program for updating, removing errors,
                        changing requirements, etc.
                        Algorithm
• Algorithm is an ordered sequence of finite, well
  defined, unambiguous instructions for completing a
  task.
Example of an Algorithm:
     Find the area of a circle of radius r.
     Inputs to the algorithm:
             Radius r of the circle.
     Expected output:
             Area of the circle
     Algorithm:
     Step1: Read/input the Radius r of the circle
     Step2: Compute Area = 3.14*r*r
     Step3: Print Area
                    Algorithm (Example)
• Algorithm to find the greatest among three numbers
ALGORITHM 1.
   • Step 1: Read the three numbers A, B, C.
   • Step 2: Compare A and B. If A is greater perform step 3 else perform step 4.
   • Step 3: Compare A and C. If A is greater, output “A is greatest” else output “C
     is greatest”.
   • Step 4: Compare B and C. If B is greater, output “B is greatest” else output “C
     is greatest”.
• ALGORITHM 2.
   • Step 1: Read the three numbers A, B, C.
   • Step 2: Compare A and B. If A is greater, store A in MAX, else store B in MAX.
   • Step 3: Compare MAX and C. If MAX is greater, output “MAX is greatest” else
     output “C is greatest”.
                        Flowchart
 is a diagrammatic
representation of the
logic for solving a
task.
               Control Structures
• Sequential:— instructions are executed in linear order
• Selection (branch or conditional):— it asks a true/false question
  and then selects the next instruction based on the answer
• Iterative (loop):— it repeats the execution of a block of
  instructions.
                                                       Iterative (loop)
Sequence                   Selection
Examples of Flowchart
1. Flowchart of a program that computes
    product of any two numbers
Examples of Flowchart
3. Flowchart of a program that
   finds the sum of first 100 integers
Examples of Flowchart
3. Flowchart n=1