Videos Related with Program Logic and Procedures

Note on Program Logic and Procedures

  • Note
  • Things to remember
  • Videos
  • Exercise
  • Quiz

Program Logic or Structure

All types of program have different module and logic. It uses three types of logic: Sequence, Selection and Iteration.

Sequence

Sequence is a set of computer instruction which follow one another and are executed unconditionally. In sequencing, instructions are put in a predefined order and computer executes the instructions only after the completion of previous one.

For example, a program to generate sum and product of two numbers might be as follows:

  • Read the values for the variables. i.e. x and y.
  • Calculate, sum = x+y
  • Calculate, product= x*y
  • Display the sum and product.

Selection

ifelse_statement.png

Selection is a set of computer instructions which are executed conditionally that is, they are executed on the basis of conditions that can be true or false when the program is executed.

If then
execute the statement A (no else)
If then
execute statement Aelse
execute statement B
if then
statement A
else if then
statement B
else if then
statement C¦.
else statement nth

Iteration (Loop)

Iteration is one in which a set of computer instructions are executed repeatedly and conditionally that is, the loop statements are driven by the loop condition. Iteration is also called looping.

Some examples of iteration (looping in programming are as follows:

Procedure and program

Procedure is a mechanism of doing or performing job of task in a well suited manner or in a correct way .so ,in the computer programming also ,procedure is way of defining,calling and handling various functions in an effective manner to make a program short and efficient.

Program is a set of computer instruction executed in such a manner that after the complete execution of instruction leads to completion a task or job. A program may consist of number of procedure of complete the task or solve the problem.For example,if a calculator is a program than addition is one of its function and the way of defining and calling this function is a procedure.

Some examples of Algorithm and Flowchart.

1. An algorithm and flowchart to generate sum of first N natural numbers.

Solution Algorithm
Step 1: Start
Step 2: Read an integer value i.e. N
Step 3: Assign, i=1.
Step 4: Calculate, Sum= Sum+ i. Increase i by 1.
Step 5: If i<=N then go to Step 4. Else go to step 6.
Step 6: Display Sum.
Step 7: End.

2. An algorithm and a flowchart to determine whether a given number is odd or even.

Solution Algorithm
Step 1: Start
Step 2: Read a number "n".
Step 3: Calculate, the remainder of n divided by 2 (i.e. n/2) that is rem=%2.
Step 4: If the rem=0 then Display "n" is even number and go to end. Else go to Step 5.
Step 5: Display "n" is odd.
Step 6: End.

3. Algorithm and flowchart to determine the largest of three given numbers.

Solution Algorithm
Step 1: Start.
Step 2: Read three numbers and store them as x, y, z.
Step 3: Compare x and y. If x is greater than y then go to step 6 else go to step 4.
Step 4: Compare y and z. If y is greater than z then print "y is largest" and go to step 8 otherwise go to step 5.
Step 5: Print "z is largest" and go to step 8.
Step 6: Compare x and z. If x is greater than z then print "x is largest" and go to step 7.
Step 7: Print "z is largest" and go to step 8.
Step 8: End

  • Sequence is a set of computer instruction which follow one another and are executed unconditionally.
  • Selection is a set of computer instructions which are executed conditionally that is, they are executed on the basis of conditions that can be true or false when the program is executed.
  • Iteration is one in which a set of computer instructions are executed repeatedly and conditionally that is, the loop statements are driven by the loop condition.
  • Procedure is a mechanism of doing or performing job of task in a well suited manner or in a correct way.
.

Very Short Questions

0%
  • ________ is a set of computer instructions which are executed conditionally that is, they are executed on the basis of conditions that can be true or false when the program is executed.

    Logic 
    Data flow 
    Sequence 
    Selection 
  • ____________  is a set of computer instruction which follow one another and are executed unconditionally.

    Flow of data 
    Selection 
    Logic 
    Sequence 
  • x*y denotes ________

    multiplication 
    division 
    addition 
    subtraction 
  • Iteration is also known as ________.
    If then statement 
    While wend statement 
    Loop statement 
    Select case statement 
  • _______ is a mechanism of doing or performing job of task in a well suited manner or in a correct way .

    Program 
    Procedure 
    User 
    Manager 
  • You scored /5


    Take test again

DISCUSSIONS ABOUT THIS NOTE

You must login to reply

Forum Time Replies Report
to find a number is odd or even

no


You must login to reply

Aaron Sapkota

How to find greatest one among three different numbers?


You must login to reply

Prabesh

How to find whether the given number is prime or composite?


You must login to reply