Desviacion Estandar Y Varianza C#
Enviado por jorge19911991 • 4 de Febrero de 2015 • 599 Palabras (3 Páginas) • 2.699 Visitas
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication37
{
class Program
{
static void Main(string[] args)
{
string[] ar;
ar = new string[10];
for (int i = 0; i < ar.Length; i++)
{
Console.WriteLine(" número {0}", i + 1);
ar[i] = Console.ReadLine();
if (ar[i] == "")
{ ar[i] = "0"; }
}
Console.WriteLine("desviacion standar = {0}", desviacion(ar));
Console.WriteLine("promedo = {0}", prom(ar));
Console.WriteLine("varianza = {0}", varianza(ar));
Console.ReadLine();
}
static double prom(string[] ar)
{
double suma = 0, prom = 0;
for (int i = 0; i < ar.Length; i++)
{
suma += Convert.ToDouble(ar[i]);
}
prom = suma / ar.Length;
return prom;
}
static double desviacion(string[] ar)
{
double d = 0, sumatoria = 0;
for (int i = 0; i < ar.Length; i++)
{
sumatoria += Math.Pow(((Convert.ToDouble(ar[i])) - prom(ar)), 2);
}
d = Math.Sqrt((sumatoria) / (ar.Length - 1));
return d;
}
static double varianza(string[] ar)
{
double v;
v = Math.Pow(desviacion(ar), 2);
return v;
...