Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the code below. How can i make 11/2 = 5.5? using System; using System.Coll

ID: 3719918 • Letter: U

Question

Using the code below. How can i make 11/2 = 5.5?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Averages
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("How Many Numeric Values to Average?");
int size = Convert.ToInt32(Console.ReadLine());
int[] n = new int[size]; /* n is an array of size integers */
/* initialize elements of array n */
Console.WriteLine("Enter " + size + " Numeric Values into array");
for (int i = 0; i <size; i++)
{
n[i] = Convert.ToInt32(Console.ReadLine());
}
Program avr = new Program();
avr.displayAverage(n);
Console.Read();
}
public void displayAverage(int[] array)
{
int sum = 0;
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
sum = sum + array[i];

}
decimal avg = sum / array.Length;
int a = Decimal.ToInt32(avg);   
Console.WriteLine("-- Average is " + (a));
}
}
}

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Averages
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("How Many Numeric Values to Average?");
int size = Convert.ToInt32(Console.ReadLine());
int[] n = new int[size]; /* n is an array of size integers */
/* initialize elements of array n */
Console.WriteLine("Enter " + size + " Numeric Values into array");
for (int i = 0; i <size; i++)
{
n[i] = Convert.ToInt32(Console.ReadLine());
}
Program avr = new Program();
avr.displayAverage(n);
Console.Read();
}
public void displayAverage(int[] array)
{
int sum = 0;
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
sum = sum + array[i];

}
decimal avg = sum /(decimal) array.Length;
Console.WriteLine("-- Average is " + (avg));
}

}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote