Answer to Question #8307 in C++ for Eugine

Question #8307
an algorithm to find the average of the numbers in a linked list of numbers
1
Expert's answer
2012-04-12T09:43:45-0400

To find the average of numbers in a linked list you should calculate the total number of this numbers (N), calculate the sum of all this numbers (Sum). So the
expected value is Sum / N.



list l;

int sum = 0;

int n = 0;

while (l.next != 0) {

sum += l.number;

n++;

l = l.next;

}

return (float) sum / n;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS