In: Computer Science
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
Code to copy:
using System;
class aggreagate
{
static void Main()
{
//First we take
user input for num_arrber 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_arr =
new int[n];
//We use for
loop to take n num_arrbers as input and assign to array
for(int i = 0; i
< n ; i++)
{
Console.Write("Enter Number "+(i+1)+" :
");
num_arr[i] =
Convert.ToInt32(Console.ReadLine());
}
//Initialising
Variables
int sum_arr = 0,
min_arr = num_arr[0], max_arr = num_arr[0];
//We again use
for loop to go through values to fond sum_arr, min_arr and
max_arr
for(int i = 0; i
< n ; i++)
{
if(num_arr[i] < min_arr)
{
min_arr =
num_arr[i];
}
if(num_arr[i] > max_arr)
{
max_arr =
num_arr[i];
}
sum_arr = sum_arr + num_arr[i];
}
//Calculating
Range and Average
double avg =
(1.0 * sum_arr)/n;
int range =
max_arr - min_arr;
//Printing
results
Console.WriteLine("Minimum: "+min_arr);
Console.WriteLine("Maximum: "+max_arr);
Console.WriteLine("Average: "+avg);
Console.WriteLine("Range: "+range);
}
}
Code Screenshot:
Output Screenshot: