Write a C function that computes the average of all numbers on the stack.


Difficulty level
Video recording
This exercise is mostly suitable for students
double average(stack s)
{
	element e;
	int sum=0, count=0;
	while(Top(s,&e))
	{
		Pop(&s);
		sum+=e;
		count++;
	}
	return sum*1.0/count;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Determinant of a 3 x 3 matrix