Write an algorithm to find the largest element in an array.

Write an algorithm to find the largest element in an array.
 

Answer:

Algorithm (Largest element in Array)

        1. K:=1, LOC:=1, MAX:=DATA[1]
        2. K=K+1.
        3. IF (K>N), then :
Write: LOC,MAX, and Exit.
       4. IF MAX < DATA [K], then
LOC:= K and MAX:= DATA [k]
5.      Go to step 2.

No comments

Dear Members, Thanks for Your Comments. We must be reply your comment answer as soon as possible. Please Stay with us.....

Theme images by ideabug. Powered by Blogger.