ALGORITHM:
A step by step
procedure to solve the given problem is known
as algorithm.
Example 1)
To find the sum, product and division of two numbers?
Step 1: Read
A and B
Step 2: sum
A+B
Step 3: prod
A*B
Step 4: div
A/B
Step 5: print
sum prod and div
Step 6: End
Example 2) To
find the Maximum value of given two numbers?
Step 1: Read
A and B
Step 2: Max
A
Step 3: If
max
Step 4: Print
max
Step 5: End
Example 3)To
find the Maximum value of given three numbers?
Step 1: Read
A,B and C
Step 2: Max=A
Step 3: If
max
Step 4: If
max
Step 5: Print
max
Step 6: End
Example
4)To Check given number is even or odd?
Step 1: Read
n
Step 2: if
n%2==0 then print "n is even
else
print"n is odd"
Step 3: End
Example 5)To
print natural numbers from 1 to given number?
Step 1: Read
n
Step 2: i=1
Step 3: print
i
Step 4: i=i+1
Step 5: if
i<=n then goto step 3
Step 5: End
Example 6)Display
factors of given number ?
Step 1: Read
n
Step 2: i=1
Step 3: if
n%i=0 then print i
Step 4: i=i+1
Step 5: if
i<=n then goto step3
Step 6: End
Example 7)To
print even numbers from 1 to given number?
Step 1: Read
n
Step 2: i=1
Step 3: if
i%2=0 then print i
Step 4: i=i+1
Step 5: if
i<=n then goto step3
Step 6: End
Example 8)To
check whether the given number is Prime or not?
Step 1: Read
n
step 2: i=1,count=0
Step 3: if
n%i=0 then count=count+1
step 4: i=i+1
step 5: if
i<=n then go to step 3
step 6: if
count=2 then print "n is prime"
else
print "n is not prime"
step 7: End
Example 9)Display sum of n natural numbers?
Step 1:Read n
step 2:i=1,sum=0
step 3:sum=sum+i
Step 4:i=i+1
step 5:if i
step 6:print sum
step 7:End
Example 10)Display reverse number of a given number?
Step 1:Read n
step 2:rev=0
Step 3:rev=rev*10=(n%10)
step 4:n=n/10
step 5:if n>0 then goto step3
step 6:print rev
step 7:End
Example 11)Display Factorial of given number?
Step 1:Read n
step 2:fact=1
Step 3:fact=fact*n
step 4:n=n-1
step 5:if n>=1 then goto step3
step 6:print fact
step 7:End
Example 12)Display number of digits of the given number?
Step 1:Read n
step 2:nd=0
step 3:nd=nd+1
step 4:n=n/10
step 5:if n>0 then go to step 3
step 6:print nd
step 7:End
Example 13)Display the sum of digits of the given number?
Step 1:Read n
step 2:sum=0;
Step 3:sum=sum+(n%10)
step 4:n=n/10
step 5:if n>0 then goto step3
step 6:print sum
step 7:End