This is a Java program to find average of N numbers.
Generally average is calculated as the sum of all the numbers divided by total numbers.
Average = (n1+n1+.........)/N
PROGRAM :
OUTPUT :
Generally average is calculated as the sum of all the numbers divided by total numbers.
Average = (n1+n1+.........)/N
PROGRAM :
package codingcorner.in;
import java.util.Scanner;
public class Average {
public static void main(String[] args) {
int n, i, numbers, sum = 0;
float avg;
Scanner scan = new Scanner(System.in);
System.out.print("Enter how many numbers do u want find the average :\t");
n = scan.nextInt();
for (i = 1; i <= n; i++) {
System.out.print("\tEnter number" + i + " \t");
numbers = scan.nextInt();
sum = sum + numbers;
}
scan.close();
avg = sum / n;
System.out.println("\tAverage of " + n+ " numbers you have entered is : " + avg);
}
}
OUTPUT :
No comments:
Post a Comment