Wednesday, 13 August 2014

Example of Various Algorithms


* Sum of n natural numbers */

1. Read the value of n.
2. i = 1 , SUM = 0
3. if ( i > n ) go to 7
4. S = S + i
5. i = i + 1
6. go to 3
7. Display the value of S
8. Stop

/* Factorial of n numbers */


1. Read the value of n.
2. i = 1 , F =1
3. if ( i > n ) go to 7
4. F = F * i
5. i = i + 1
6. go to 3
7. Display the value of S
8. Stop

/* To Find the value of xn */

1. Read the value of n.
2. i = 1 , m = 1
3. If i > n then go to 7
4. m = m * x
5. i = i + 1
6. go to 3
7. Display m
8. Stop