Sunday 12 December 2010

Algorithm for To find both the largest and smallest number in a list of integers

Objective : 9

To find both the largest and smallest number in a list of integers

Description:


This program contains n number of elements, in these elements we can find the largest and smallest numbers and display these two numbers

Algorithm:


Step 1: start Step 2: read n

Step 3: initialize i=0
Step 4: if i<n do as follows. If not goto step 5 Read a[i]
Increment i
Goto step 4

Step 5: min=a[0], max=a[0]
           Step 6: initialize i=0

Step 7: if i<n do as follows. If not goto step 8
            If a[i]<min
 Assign min=a[i]
 increment i goto Step 7

Step 8: print min,max
Step 9: stop

Output:

1. enter the array size:4
Enter the elements of array 36 13 2 45
maximum value is:45
    minimum value is:2
2.enter the array size:5
Enter the elements of array 6 2  1   3 8
maximum value is:8
minimum value is:1
3.enter the array size:5
Enter the elements of array-6 9 -9 2 5
   maximum value is:9
minimum value is:-9

conclusion: the program is error free

VIVA QUESTIONS:

1) What is an array ?
Ans: The collection of similar elements is called array
2) How many types of arrays are there ?
 Ans: Three types. They are one dimensional ,two dimensional and multi dimensional arrays




C for Loop Examples

No comments:

Post a Comment