
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
Arreglo H;
Arreglo F;
double dat1, dat2;
double s = 0, numerador, denominador;
int I = 1, num;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
num = int.Parse(textBox1.Text);
H = new Arreglo(num);
F = new Arreglo(num);
}
private void button2_Click(object sender, EventArgs e)
{
if (I < num)
{
dat1 = double.Parse(textBox2.Text);
H.elementos[I] = dat1;
dat2 = double.Parse(textBox3.Text);
F.elementos[I] = dat2;
}
if (I == num)
{
for (I = 0; I < num; I++)
{
s = s + H.elementos[I] * F.elementos[I];
}
numerador = num * s - H.sumadatos(num) * F.sumadatos(num);
denominador = Math.Sqrt((num * H.sumacuadrada(num) - (Math.Pow(H.sumadatos(num), 2))) * (num * F.sumacuadrada(num) - (Math.Pow(F.sumadatos(num), 2))));
listBox1.Items.Add(numerador / denominador);
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
}
I ++;
textBox2.Clear();
textBox3.Clear();
textBox2.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication3
{
class Arreglo
{
double[] Elementos;
public Arreglo(int N)
{
Elementos = new double[N];
}
public double[] elementos
{
get { return Elementos; }
set { Elementos = value; }
}
public double sumacuadrada(int N)
{
double sum = 0;
int I;
for (I = 0; I < N; I++)
{
sum = sum + Math.Pow(Elementos[I], 2);
}
return sum;
}
public double sumadatos(int N)
{
double suma = 0;
int I;
for (I = 0; I < N; I++)
{
suma = suma + Elementos[I];
}
return suma;
}
}
}
No hay comentarios:
Publicar un comentario