FIND THE AVERAGE OF ARRAY
What is the Average?
The average (or mean) of a dataset is calculated by dividing the sum of all elements by the number of elements. It offers a quick way to understand the overall trend or distribution of values.
Formula:
Steps to Calculate the Average
- Input: Start with an array of numbers.
- Sum: Add up all the elements in the array.
- Divide: Divide the sum by the total number of elements.
Example:
For the array
- Sum =
- Number of elements =
- Average =
CODE
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
int sum=0;
int n=sc.nextInt();
for(int i=0;i<n;i++){
sum+=sc.nextInt();
}
System.out.print(sum/n);
}
}
No comments:
Post a Comment