# solutions19 - Find maximum value in list max = list[0...

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

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

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

View Full Document
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<len; k++) { if (list[k] > max) { max = list[k]; } } // Return maximum value return max; } float avglist( int list[ ], int len) //PURPOSE: find average of a list //PRECONDITIONS: 0<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<len; k++) { sum = sum + list[k]; } // Compute average of list avg = ( float ) sum / ( float ) len; // Return average of list return avg; }...
View Full Document

## This homework help was uploaded on 04/16/2008 for the course CSCI 1100 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

### 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
Ask a homework question - tutors are online