Friday, 13 November 2015

Basics of Flowchart, Pseudocode, Algorithm and Computer Program





Algorithm, Program ,Pseudocode and Flowchart

 


Algorithm and Programs

Algorithm: a method or a process followed to solve a problem.

An algorithm takes the input to a problem (function) and transforms it to the output. A problem can have many algorithms.
Algorithm posses the following properties:
1.      It must be correct.
2.      It must be composed of a series of concrete logical steps in proper sequence.
3.      There can be no ambiguity as to which step will be performed next.
4.      It must be composed of a finite number of steps.
5.      It must terminate.

 

A computer program is an instance of concrete representation, for an algorithm in some programming.



  Example of Simple C Program:
#include<stdio.h>

int main()
{
   int a, b, c;

   printf("Enter two numbers to add\n");
   scanf("%d%d",&a,&b);
    c = a + b;
    printf("Sum of entered numbers = %d\n",c);

   return 0;
}



Pseudocode:

Pseudocode is an informal high-level English-like representation or description of the operating principle of a computer program or other algorithm logic. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading. It consists of an extended version of the basic algorithmic constructs: sequence, selection, and iteration.

Features of  PseudoCode:
 

  •  Algorithm Header
  •    Purpose, Condition, sequence and Return
  •   Statement Numbers   
  • Keyword and indentation with no fixed syntax 
  • Variables
  •   Constructive Statement

Pseudocode Example
Express an algorithm to get two numbers from the user (dividend and divisor), testing to make sure that the divisor number is not zero, and displaying their quotient using pseudocode

Example 1:

1. Declare variables: dividend, divisor, quotient
2. Prompt user to enter dividend and divisor
3. Get dividend and divisor
4. IF divisor is equal to zero, THEN
4.1. DO
4.1.1. Display error message, “divisor must be non-zero”
4.1.2. Prompt user to enter divisor
4.1.3. Get divisor
4.2. WHILE divisor is equal to zero
5. ENDIF
6. Display dividend and divisor
7. Calculate quotient as dividend/divisor
8. Display quotient



 
Example 2:

Unable to Load Image


Flowchart:
 A graphical tool that diagrammatically depicts the steps and structure of an algorithm or program. The following shapes are often used in flowcharts:


Unable to Load Image
Basic Flow Chart Symbols

 Example of Pseudocode and Flow chart

Pseudocode and Flow chart of a problem