Write a C function that adds all the numbers on the stack together.
Difficulty level
Video recording
This exercise is mostly suitable for students
int add(stack s)
{
element e;
int sum=0;
while(Top(s,&e))
{
Pop(&s);
sum+=e;
}
return sum;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Derivative approximation