English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

float average(float array[]) {
float sum=0;
for (int i=0; i sum += array[i];
return sum / (float) array.length;
}

Note: There's no random "catch (Exception e)" in the code, that syntax (produced by an earlier respondent) is invalid.

2007-07-24 15:56:29 · answer #1 · answered by McFate 7 · 0 0

Iterate through the array (with a for loop), from first to last, and add up all the numbers. Then, divide by 50, and you've got the average.

2007-07-24 14:45:40 · answer #2 · answered by so far north 3 · 2 1

that easy:

// float array[] ... is the numbers

float sum = 0;
try for (int x = 0; ; x++) sum = sum + array[x];
catch (Exception e) ;
float answer = sum / array.length;

2007-07-24 14:54:16 · answer #3 · answered by Andy T 7 · 0 2

fedest.com, questions and answers