Matrices

Páginas: 6 (1292 palabras) Publicado: 3 de julio de 2012
EJERCICIO PRÁCTICA DE C#
OPERACI0NES CON VECTORES

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ejemplo2
{
public partial class Ejemplo2: Form
{
int[] V = new int[100];
int Max;
public Ejemplo2()
{InitializeComponent();
}

void OrdenarVector(int[] V)
{
int Inc,tmp,j;
Inc=Max/2;
do{
for(int i=Inc;i<Max;i++)
{
tmp=V[i];
j=i-Inc;
while((j>=0)&&(tmp<V[j]))
{
V[j+Inc]=V[j];
j-=Inc;
}
V[j+Inc]=tmp;}
Inc/=2;
}while(Inc!=0);
}

void Generar(int[] V)
{
Max = Convert.ToInt32(Cantidad.Text);

DateTime tmeNow = DateTime.Now;
int mls = tmeNow.Millisecond;
// Generate two random numbers between 100 and 999
Random rndNumber = new Random(mls);
for (int i = 0; i <Max; i++)
{

V[i] = rndNumber.Next(0, 100);
}
OrdenarVector(V);

}
public void MostrarVector(int[] V, int M)
{
Resultado.Text="";
for(int i=0;i<M;i++)
Resultado.Text+="\r\n"+V[i];
}

int Busqueda(int[] V)
{ intInf,Sup,Cen=0,Dato;
Boolean NoEncontrado;
Dato=Convert.ToInt32(InputBox.ShowInputBox("Ingrese número a buscar","Vectores","0"));
Inf=0;
Sup=Max-1;
NoEncontrado=true;
while(Inf<=Sup && NoEncontrado)
{ Cen=(Inf+Sup)/2;
if(V[Cen]==Dato)
NoEncontrado=false;
else
if(V[Cen]<Dato)Inf=Cen+1;
else
Sup=Cen -1;
}
if(NoEncontrado)
return -1;
else
return Cen;
}

int Repeticiones (int[] V)
{
int Dato,c;
Dato=Convert.ToInt32(InputBox.ShowInputBox("Ingrese número a ver repeticiones","Vectores","0"));
c=0;
for(int i=0;i<Max;i++)if(V[i]==Dato)
c++;
return c;
}
private void Mostrar_Click(object sender, EventArgs e)
{
MostrarVector(V,Max);
}

private void GenerarVector_Click(object sender, EventArgs e)
{
Generar(V);
}

private void Buscar_Click(object sender, EventArgs e)
{
int pos;pos = Busqueda(V);
if (pos < 0)
MessageBox.Show("No Encontrado");
else
MessageBox.Show("Encontrado en posición "+(pos+1));
}

private void VerRepeticiones_Click(object sender, EventArgs e)
{
int r;
r=Repeticiones(V);
MessageBox.Show("Se encontraron "+r+"repeticiones");
}

private void VerParImpar_Click(object sender, EventArgs e)
{
Menu2 MenuParImpar=new Menu2(V,Max);
MenuParImpar.ShowDialog();
}

private void Borrar_Click(object sender, EventArgs e)
{
Resultado.Text = "";
Cantidad.Text = "";
Cantidad.Focus();
}private void Cerrar_Click(object sender, EventArgs e)
{
Application.Exit();
}


}
public class InputBox : System.Windows.Forms.Form
{

#region "Atributos"
private System.Windows.Forms.Label lblInfo;
private System.Windows.Forms.TextBox txtTexto;
private System.Windows.Forms.Button button1;
private...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Matrices
  • Matrices
  • matrices
  • MATRICES
  • Matrices
  • Matrices
  • Matrices
  • matrices

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS