Computer Science, asked by Nitinarya498, 1 month ago

The principal of a school wants to speak with some of the students to assess their overal development including studies. Most of the teachers were selecting the toppers of their classes but Mr. Sam thought of an idea to select the bunch of students who did not have much difference in their marks so that he gains the reputation of a teacher who teaches well to the whole class and not just to a bunch of brilliant students

You are required to help Mr Sam in selecting K students that can speak with the principas from his class. You need to return an integer array representing the marks of the selected students sorted in ascending order.

Input Specification:

input1: An integer value denoting the number of students in Mr. Sam's class input2: An integer array of size input1 representing the marks of each student. input3: An Integer K denoting the number of representatives to be selected

Output Specification:

Return an integer array containing the marks of K selected students sorted in ascending order

Answers

Answered by shardasingh6
5

Answer:

jd ksh sjahgejgsuhsheeheua

Answered by shilpa85475
30

nput1: An integer value denoting the number of students in Mr. Sam's class

input2: An integer array of size input1 representing the marks of each student.

input3: An Integer K denoting the number of representatives to be selected

Explanation:

import java.util.*;

public class MyClass {

   public static void main(String args[]) {

    Scanner sc = new Scanner(System.in);  

 

 int row = sc.nextInt();    

 int col = sc.nextInt();

 int avg[]= new int[row];

 int ans[] = new int[row];

 int arr[][]= new int[row][col];

 int res[]= new int[row];

 for(int i = 0; i <row; i++) {

  for(int j=0;j<col;j++) {

   arr[i][j]= sc.nextInt();

  }

 }

 

 /*//verifying i/p

 for(int i = 0; i <row; i++) {

  for(int j=0;j<col;j++) {

   System.out.print(arr[i][j]+" ");

  }

  System.out.println("");

 }*/

 

 for(int i = 0; i <row; i++) { //calculating and storing average of each column

  for(int j=0;j<row;j++) {

  ans[i] += arr[j][i];

 

  }

 avg[i] = ans[i]/row;  

 

 }

 

int min = avg[0];

 int eleminate_Index =0;

 for(int i = 1; i < row; i++) { // minimum average calculated and ..

  if(avg[i]<min) {

   min = avg[i];

   eleminate_Index = i; //..index of it stored.

  }

 }

 

 /*

 System.out.println(min);

 System.out.println(p);

 */

 for(int i = 0 ; i<row; i++) {

  for(int j=0; j<col; j++){

   if(eleminate_Index!=j) {//calculating sum of remaining subjects

    res[i]+=arr[i][j];

   }

 }

   

 }

 for(int j=0; j<row; j++){

  System.out.print(res[j]+" ");

  }

sc.close();

   }

}

Similar questions