# Answer to Question #16204 in C# for valarie

Question #16204

Create a program that will prompt an end user to input 5 float-type values, then calculate the mean, the variance and the standard deviation. I am so lost, need any help avaiable.

Expert's answer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication6

{

class Program

{

static void Main(string[] args)

{

double[] array1 = new double[5];

for (int i = 0; i < 5; i++)

{

Console.Write("Enter value for " + (i + 1).ToString() + ": ");

array1[i] = int.Parse(Console.ReadLine());

}

Console.WriteLine("Mean= " + ArithmeticMean(array1, 5).ToString());

Console.WriteLine("Standard Deviation= " + StandardDeviation(array1, 5).ToString());

Console.WriteLine("Variance= " + Variance(array1, 5).ToString());

Console.ReadLine();

}

static double StandardDeviation(double[] data, int items)

{

int i;

double SD, mean, devMean;

double[] deviation = new double[items];

mean = ArithmeticMean(data, items);

for (i = 0; i < items; i++)

{

deviation[i] = Math.Pow((data[i] - mean), 2);

}

devMean = ArithmeticMean(deviation, items);

SD = Math.Sqrt(devMean);

return SD;

}

static double ArithmeticMean(double[] data, int items)

{

int i;

double mean, sum;

sum = 0.0;

for (i = 0; i < items; i++)

{

sum += data[i];

}

mean = sum / (double)items;

return mean;

}

static double Variance(double[] data, int items)

{

int i;

double variance, mean;

double[] deviation = new double[items];

mean = ArithmeticMean(data, items);

for (i = 0; i < items; i++)

{

deviation[i] = Math.Pow((data[i] - mean), 2);

}

variance = ArithmeticMean(deviation, items);

return variance;

}

}

}

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication6

{

class Program

{

static void Main(string[] args)

{

double[] array1 = new double[5];

for (int i = 0; i < 5; i++)

{

Console.Write("Enter value for " + (i + 1).ToString() + ": ");

array1[i] = int.Parse(Console.ReadLine());

}

Console.WriteLine("Mean= " + ArithmeticMean(array1, 5).ToString());

Console.WriteLine("Standard Deviation= " + StandardDeviation(array1, 5).ToString());

Console.WriteLine("Variance= " + Variance(array1, 5).ToString());

Console.ReadLine();

}

static double StandardDeviation(double[] data, int items)

{

int i;

double SD, mean, devMean;

double[] deviation = new double[items];

mean = ArithmeticMean(data, items);

for (i = 0; i < items; i++)

{

deviation[i] = Math.Pow((data[i] - mean), 2);

}

devMean = ArithmeticMean(deviation, items);

SD = Math.Sqrt(devMean);

return SD;

}

static double ArithmeticMean(double[] data, int items)

{

int i;

double mean, sum;

sum = 0.0;

for (i = 0; i < items; i++)

{

sum += data[i];

}

mean = sum / (double)items;

return mean;

}

static double Variance(double[] data, int items)

{

int i;

double variance, mean;

double[] deviation = new double[items];

mean = ArithmeticMean(data, items);

for (i = 0; i < items; i++)

{

deviation[i] = Math.Pow((data[i] - mean), 2);

}

variance = ArithmeticMean(deviation, items);

return variance;

}

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment