write a program to find the average number in an integer array of size 15.
Answers
Answered by
1
Answer:
Explanation:
Average is the sum of array elements divided by the number of elements. Examples : Input : arr[] = {1, 2, 3, 4, 5} Output : 3 Sum of the elements is 1+2+3+4+5 = 15 and total number of elements is 5.First of all, we will find the sum of the series and then divide this sum by the number of terms to get the average. We know that sum, S = n(n+1)/2.Source Code to Calculate Average Using Arrays
Then, the for loop gets all the elements from the user and stores the sum of the entered numbers in sum . Finally, the average is calculated by dividing sum by the number of elements n .
Similar questions