Algorithm Average of a set of numbers numbers #c

/* To display Average of a set of given numbers. */

1. Read the value of n.
2. i = 1 , SUM = 0.
3. if  i > n go to 9
4. Read the value of x.
5. SUM = SUM + x
6. i = i + 1
7. go to 3
8. AVERAGE = SUM / n
9. Display AVERAGE.
10. Stop

* x is user defined numbers.

/* To display Largest of a set of given positive numbers. */ 

1. Read the value of n.
2. i = 0 , Y= 0
3. if i <= n go to 7
4. Read the value of X
5. If X > Y then Y = X
6. go to 3
7. Display Y
8. Stop

/* To display Latgest of a set of given numbers. */  

1. Read the value of n.
2. i = 0
3. if i <= n go to 7
4. Read the first number in X
5. S = X
6. i = i + 1
7. If  i > n go to
8. Read the Second number in X
9. If X > S then S = X
10. go to 4
11. Display S
12. Stop

/* To display Smallest of a set of given numbers. */  

1. Read the value of n.
2. i = 0
3. if i <= n go to 7
4. Read the first number in X
5. S = X
6. i = i + 1
7. If  i > n go to
8. Read the Second number in X
9. If X < S then S = X
10. go to 4
11. Display S
12. Stop


 ***** To display the smallest value in set of numbers you need two numbers to compare. But in the case of To display largest of two numbers we can take one number as "0" so we need only one number (This is only for positive numbers). *****

Comments

Popular posts from this blog

Algorithm to display "n" natural numbers #c

Algorithm to display the sum of n natural numbers #c

Algorithm for Sum of two numbers