Question

Write a program, using C#, that will find the mean and standard deviation of a number...

Write a program, using C#, that will find the mean and standard deviation of a number of data points. The program should allow the user to enter data manually or via a text file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
public class HelloWorld
{
// Main method which starts the program execution.
public static void Main()
{
int n;

float deviation, sum, sumsqr, mean, variance, stddev;
  
Console.Write("Enter number of elements:");
n = int.Parse(Console.ReadLine());
float[] num = new float[n];
sum = 0;
sumsqr = 0;
/* Reading array elements */
Console.WriteLine("Input " + n + " values");
for (int i = 0; i < n; i++)
{
num[i] = float.Parse(Console.ReadLine());
sum += num[i];

}

mean = sum / (float)n;
Console.WriteLine("Mean is "+ mean);
for (int i = 0; i < n; i++)
{
deviation = num[i] - mean;
sumsqr += deviation * deviation;
}
/* variance */
variance = sumsqr / (float)n;
stddev = (float)Math.Sqrt(variance);
Console.WriteLine("Standard Deviation is " + stddev);
Console.WriteLine("Variance is " + variance);
Console.ReadKey();
}
}

if you have any doubts please ping me in the comment section below,thank you

Add a comment
Know the answer?
Add Answer to:
Write a program, using C#, that will find the mean and standard deviation of a number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT