Page 412 - CA_Blue( J )_Class10
P. 412
System.out.print(a[i] + "\t");
}
}
17. 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] [2018]
Ans. import java.util.*;
class question_9
{
public static void main()
{
Scanner sc= new Scanner(System.in);
int n,i;
System.out.print("Number of students: ");
n=sc.nextInt();
String name[] = new String[n];
int totalmarks[] = new int[n];
double avg = 0.0, dev = 0.0;
for(i = 0; i < n; i++) {
System.out.print("Enter Name: ");
name[i] = sc.next();
System.out.print("Enter Marks: ");
totalmarks[i] = sc.nextInt();
avg += totalmarks[i];
}
avg = avg/n;
for(i = 0; i < n; i++)
{
dev = totalmarks[i] - avg;
System.out.println("Deviation " + (i + 1) + ": " + dev);
}
System.out.println("Average score: " + avg);
}
}
18. Write a program to input integer elements into an array of size 20 and perform the following operations: [2017]
(i) Display the largest number from the array.
(ii) Display the smallest number from the array.
(iii) Display sum of all the elements of the array.
Ans. import java.util.*;
class program
{ public static void main()
{ Scanner sc= new Scanner(System.in);
int ar[] = new int[20];
int sum = 0, l, s, i;
System.out.println("Enter 20 elements:");
for( i = 0; i < 20; i++)
{ ar[i] = sc.nextInt(); }
l=ar[0]; s=ar[0];
for( i = 1; i < 20; i++)
{ if(l < ar[i])
l = ar[i];
if(s > ar[i])
410410 Touchpad Computer Applications-X

