In: Computer Science
OBJECTIVE
Upon completion of this exercise, you will have demonstrated the ability to:
INTRODUCTION
Your instructor will assign one of the following projects, each involves the user of loops and the construction of conditions to control them.
CODING STANDARDS
The following coding standards must be followed when developing your program:
PROJECTS
DEMONSTRATION/SUBMISSION REQUIREMENTS
Code:
using System;
class Test
{
static void Main()
{
//First we take user input for number of inputs and assign to n after Integer Conversion
Console.Write("Enter Number Of Inputs: ");
int n = Convert.ToInt32(Console.ReadLine());
//We create an integer array of size n
int[] num = new int[n];
//We use for loop to take n numbers as input and assign to array
for(int i = 0; i < n ; i++)
{
Console.Write("Enter Number "+(i+1)+": ");
num[i] = Convert.ToInt32(Console.ReadLine());
}
//Initialising Variables
int sum = 0, min = num[0], max = num[0];
//We again use for loop to go through values to fond sum, min and max
for(int i = 0; i < n ; i++)
{
if(num[i] < min)
{min = num[i];}
if(num[i] > max)
{max = num[i];}
sum = sum + num[i];
}
//Calculating Range and Average
double avg = (1.0 * sum)/n;
int range = max - min;
//Printing results
Console.WriteLine("Minimum: "+min);
Console.WriteLine("Maximum: "+max);
Console.WriteLine("Average: "+avg);
Console.WriteLine("Range: "+range);
}
}