English

The annual examination result of 50 students in a class is tabulated in a Single Dimensional Array (SDA) is as follows: - Computer Applications

Advertisements
Advertisements

Question

The annual examination result of 50 students in a class is tabulated in a Single Dimensional Array (SDA) is as follows: 

Roll No. Subject A Subject B Subject C
..................... ..................... ..................... .....................
..................... ..................... ..................... .....................
..................... ..................... ..................... .....................

Write a program to read the data, calculate and display the following:

  1. Average marks obtained by each student.
  2. Print the roll number and the average marks of the students whose average is above 80.
  3. Print the roll number and the average marks of the students whose average is below 80.
Answer in Brief

Solution

import java.util.Scanner;
class Q11{
public static void main(String args[])
{
Scanner sn = new Scanner(System.in);
int i;
int roll[] = new int[50]; // Change to 4 during testing
String name[] = new String[50];
double A[] = new double[50]; // subject A
double B[] = new double[50]; // subject B
double C[] = new double[50]; // subject C
double avg[] = new double[50];

for (i = 0; i < roll.length; i++)
{
System.out.print("\n\nroll number: ");
roll[i] = sn.nextInt();
System.out.print("Name: ");
name[i] = sn.next();
System.out.print("Sub. A mark: ");
A[i] = sn.nextDouble();
System.out.print("Sub. B mark: ");
B[i] = sn.nextDouble();
System.out.print("Sub. C mark: ");
C[i] = sn.nextDouble();

avg[i] = (A[i] + B[i] + C[i]) / 3;
System.out.println("Average = " + avg[i]);
}

System.out.println("\n*** AVERAGE > 80 ***");
for (i = 0; i < roll.length; i++)
{ if (avg[i] > 80)
System.out.println("Roll no: " + roll[i] + " Average: " + avg[i]);
}

System.out.println("\n*** AVERAGE <80 ***");
for (i = 0; i < roll.length; i++)
{ if (avg[i] < 80)
System.out.println("Roll no: " + roll[i] + " Average: " + avg[i]);
}
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [Page 241]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 3 Arrays (Single Dimensional and Double Dimensional)
EXERCISES | Q VII. 11. | Page 241
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×