Skip to content

Programming Logic

What is to be expressed to the system
or
how to write instructions to the system
Logic building tools:
1. Algorithm
2. psuedocode
3. flow chart
Algorithm
it is a step by step solution of the given problem expressed in simple human understandable language.
Example)
write algorithm to instruct the system to store a number and display it

Solution)
1. start your program
2. reserve some amount of memory space in your RAM to store a number later
3. store value 25 into the memory allocated in step 2
4. display the value stored in the memory created in step 2 onto monitor
5. stop your program

1. start your program
2. reserve some amount of memory space in your RAM to store a number later and assign name ‘a’ to it
3. store value 25 into ‘a’
4. display the value stored in ‘a’ onto monitor
5. stop your program

psuedocode  (false code)
alternative way of representation of steps in the algorithm by using some standard notations.

1. start
2. declare ‘a’
3. a:= 25
4. Write “value of a=”,a
5. stop
c lang representation of above algorithm:
#include<stdio.h>

void main()
{
int a;
a=25;
printf(“a=%d”,a);
}

Java representation:
import java.io.*;

public class sample
{
public static void main(String []args)
{
int a;
a=25;
System.out.println(“a=”+a);
}
}

Python representation:
a=25
print(“a=”,a)

Ex)
Write algorithm(psuedocode) to
1. calculate and display sum of any two numbers
Hint:
sum:=a+b
2. display area of rectangle for desired length and breadth
Hint:
area:=len x bre

3. Write Algorithm to calculate and display area of circle for the desired radius value
Hint:
area:=3.14 x rad x rad
4. to display average of three desired numbers
Hint:
avg:=(a+b+c)/3
5. to calculate Simple Interest for the desired principle, rate of interest and duration
hint:
si:=(p x n x r)/100