SyncFusion Interview Programs with Answers

SyncFusion Interview Programs with Answers

This blog explains about SyncFusion Interview Programs with Answers and is explained below : 

______________________________________________________________________________

Let us discuss SyncFusion Interview Programs with Answers here. The below program was asked for a .NET Fresher candidate in SyncFusion Interview.

SyncFusion Interview Programs with Answers

Finding the average of Array Excluding Highest, Lowest elements in the array :

int[] arr = new int[] { 8, 8, 10,6, 8 };

if (arr.Length > 0)
{
int small = arr[0];
int large = arr[0];
for (int i = 0; i < arr.Length; i++)
{
if (large < arr[i])
{
int tmp = large;
large = arr[i];
arr[i] = large;
}
if (small > arr[i])
{
int tmp = small;
small = arr[i];
arr[i] = small;
}
}
MessageBox.Show(“smallest is ” + small.ToString());
MessageBox.Show(“largest is ” + large.ToString());
int sum= 0;
for (int i = 0; i < arr.Length;i++ )
{
if(arr[i] != small && arr[i] != large)
{
sum += arr[i];
}
}
if (sum != 0)
sum /= 3;

MessageBox.Show(” The Average of the numbers is ” + sum.ToString());

}

Java Code:

import java.util.*; 
import java.io.*; 
 public class Exercise29 {
 public static void main(String[] args)
 {
    int[] array_nums = {5, 7, 2, 4, 9};
	System.out.println("Original Array: "+Arrays.toString(array_nums)); 
	int max = array_nums[0];
	int min = array_nums[0];
	float sum = array_nums[0];
	for(int i = 1; i < array_nums.length; i++)
	{
		sum  += array_nums[i];
		if(array_nums[i] > max)
			max = array_nums[i];
		else if(array_nums[i] < min)
			min = array_nums[i];
	}
	float x = ((sum-max-min) / (array_nums.length - 2));
	System.out.printf("Compute the average value of an array of integers except the largest and smallest values: %.2f",x);
	System.out.print("\n");	
  }
}

Output:

                                                                              
Original Array: [5, 7, 2, 4, 9]                                        
Compute the average value of an array of integers except the largest an
d smallest values: 5.33

Please share your views also about this program.

_______________________________________________________________________________________