Algorithm Examples
Algorithm Examples
Step 1: Start
Step 2: Declare variables a, b, sum
Step 3: Input the values of a and b
Step 4: Calculate, sum = a+b
Step 5: Display the value of sum
Step 6: Stop
2. Algorithm to display the larger value between any two numbers.
Step 1: Start
Step 2: Declare variables a,b
Step 3: Read the values of a and b
Step 4: if a>b then
display a is larger
else
display b is larger
Step 5: Stop
3. Write an algorithm and draw flowchart to check whether any integer is exactly divisible
by 3 or not.
Step 1: Start
Step 2: Declare variables n, rem
Step 3: Input the value n
Step 4: Calculate, rem = n mod 3
Step 5: if rem = 0 then
display n is exactly divisible by 3
else
display n is not exactly divisible by 3
Step 6: Stop
4. Algorithm to display the numbers from 1 to n.
Step 1: Start
Step 2: Declare variables n, i
Step 3: Input the value of n
Step 4: Initialize, i = 1
Step 5: Repeat steps 5.1 and 5.2 until i≤n
Step 5.1: Display the value of i
Step 5.2: Increase the value of i by 1 i.e. i = i+1
Step 6: Stop
[n=5,i=1,sum=0
sum=0+1=1
i=2
sum=1+2=3
i=3
sum=3+3=6 , i=4
sum=6+4=10 , i=5, sum=10+5=15 i=6 Exit step 5
sum=15 Ans.]