Challenge: Why Do We Need Array Size as an Argument?
Swipe to start coding
You are creating a student analytics tool that calculates the average score from a list of grades stored in a dynamic array.
- The function
calculateAverage
takes a pointer to an integer arrayscores
and anint
n
representing the number of elements. - Initialize a variable
sum
to0
before the loop. - Use a loop to iterate over the array from
0
ton
. - In each iteration, add the current element to the variable
sum
. - Return the average score by dividing
sum
byn
.
Example
{80, 90, 75, 85, 100} => 86.0
{60, 70, 80} => 70.0
{100, 90, 95, 85} => 92.5
Løsning
solution.cpp
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me an example?
Awesome!
Completion rate improved to 5
Challenge: Why Do We Need Array Size as an Argument?
Stryg for at vise menuen
Swipe to start coding
You are creating a student analytics tool that calculates the average score from a list of grades stored in a dynamic array.
- The function
calculateAverage
takes a pointer to an integer arrayscores
and anint
n
representing the number of elements. - Initialize a variable
sum
to0
before the loop. - Use a loop to iterate over the array from
0
ton
. - In each iteration, add the current element to the variable
sum
. - Return the average score by dividing
sum
byn
.
Example
{80, 90, 75, 85, 100} => 86.0
{60, 70, 80} => 70.0
{100, 90, 95, 85} => 92.5
Løsning
solution.cpp
Tak for dine kommentarer!
single