Saturday, February 16, 2019
COP 3530, Discrete Data Structures and Algorithms, Summer 1999, Homework 2 :: UFL Florida Computer Programming Homework
Class Notes information Structures and AlgorithmsSummer-C Semester 1999 - M WRF 2nd Period CSE/E119, Section 7344Homework 2 -- ascribable Fri 28 May 1999 09.30am * Question 1. Assume that an n-element array (vector) a contains diaphanous integers arranged in no particular order. Write an algorithm to baffle the cheer and location of (a) the mean of a and (b) the apprise v in a closest to the mean. Note If v equals the mean, then v is the value closest to the mean. Example. If a = (1,2,3,5,4,6,7,9), then the mean equals 37/8 = 4.625. The value 5, which is in the fourth location (i = 4), happens to be the value closest to the mean. purpose FindMean(a array 1..n of int) sum = 0 posmean = -1, posclose = -1 for i = 1 to n do sum = sum + ai endfor mean = float(sum) / n mdif = 9E13 for i = 1 to n do dif = abs(ai - mean) if (dif if (dif = 0) then
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment