solutions19 - // Find maximum value in list max = list[0];...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 19 -- Solutions int minlist( int list[ ], int len) //PURPOSE: find minimum value in a list //PRECONDITIONS: 0 < len, len is length of list //POSTCONDITIONS: return the minimum value in list { int k; // loop variable int min; // minimum value in list // Find minimum value in list min = list[0]; for (k=1; k<len; k++) { if (list[k] < min) { min = list[k]; } } // Return minimum value return min; } int maxlist( int list[ ], int len) //PURPOSE: find maximum value in a list //PRECONDITIONS: 0 < len, len is length of list //POSTCONDITIONS: return the maximum value in list { int k; // loop variable int max; // maximum value in list
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Find maximum value in list max = list[0]; for (k=1; k&lt;len; k++) { if (list[k] &gt; max) { max = list[k]; } } // Return maximum value return max; } float avglist( int list[ ], int len) //PURPOSE: find average of a list //PRECONDITIONS: 0&lt;len, len is length of list //POSTCONDITIONS: return average of list { int k; // loop variable int sum; // sum of numbers in list float avg; // average of numbers in list // Sum the number in the list sum = list[0]; for (k=1; k&lt;len; k++) { sum = sum + list[k]; } // Compute average of list avg = ( float ) sum / ( float ) len; // Return average of list return avg; }...
View Full Document

Page1 / 2

solutions19 - // Find maximum value in list max = list[0];...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online