Tuesday, March 26, 2019
COP 3530, Discrete Data Structures and Algorithms, Summer 1999, Homework 2 :: UFL Florida Computer Programming Homework
Class Notes Data Structures and AlgorithmsSummer-C Semester 1999 - M WRF 2nd Period CSE/E119, Section 7344Homework 2 -- Due Fri 28 May 1999 09.30am * Question 1. As couplinge that an n-element range (vector) a contains distinct integers set up in no particular order. Write an algorithm to find the harbor and location of (a) the mean of a and (b) the value v in a impendent 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. Answer 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