NPTEL 2020: PROGRAMMING IN JAVA WEEK 1:Q5 ANSWER

Complete the code segment to¬†help Raj , find the highest mark and average mark secured by him in “s” number of subjects.

//initialise maximum element as first element of array.
int max=arr[0];
double sum=arr[0];
//traverse array elements to get the current max
for(i=1;i<arr.length;i++)
{
sum=sum+arr[i];
if(arr[i]>max)
max =arr[i];
}
//Store the highest mark in the variable max
//Store average mark in avgMarks
result=max;
mark_avg=sum/(arr.length);
//Evaluation code
System.out.println(result);
System.out.println(mark_avg);

Leave a Reply

Your email address will not be published. Required fields are marked *