Question
Write a program to accept name and total marks of N number of students in two single subscripts array name[] and totalmarks[].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students) / N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class program9
{
public static void main(String[] args)
{
int sum=0,n=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of students: ");
n = sc.nextInt();
String[] name = new String[n];
int[] totalmarks = new int[n];
for (int i = 0; i< n; i++)
{
System.out.println("Student " + (i + 1));
System.out.print("Enter name of student: ");
name[i] = sc.next();
System.out.print("Enter marks: ");
totalmarks[i] = sc.nextInt();
}
for (int i = 0; i< n; i++)
{
sum = sum + totalmarks[i];
}
double average = (double) sum / n;
System.out.println("Average of all marks " + average);
for (int i = 0; i< n; i++)
{
double deviation = totalmarks[i] - average;
System.out.println("Deviation of " + name[i] + " is " + deviation);
}
}
}