viernes, 27 de noviembre de 2009

RANDOM EN C#


03.11.09 trabajo de ordenar numeros
---------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

Random objeto = new Random();
int[] arreglo = new int[50];
for (int i = 0; i < i =" 0;" j =" 0;"> arreglo[j + 1])
{
temp = arreglo[j];
arreglo[j] = arreglo[j + 1];
arreglo[j + 1] = temp;
}
}
}
Console.Write("arreglo ordenado ");
for (int i = 0; i < a =" new" b =" new" c =" new" objeto =" new" i =" 0;" j =" 0;" i =" 0;" j =" 0;" i =" 0;" j =" 0;" i =" 0;" j =" 0;" i =" 0;" j =" 0;" k =" 0;" i =" 0;" j =" 0;" objeto =" new" arreglo =" new" i =" 0;" i =" 0;" j =" 0;"> arreglo[j + 1])
{
temp = arreglo[j];
arreglo[j] = arreglo[j + 1];
arreglo[j + 1] = temp;
}
}
}
Console.Write("arreglo ordenado ");
for (int i = 0; i < 10; i++)
{
Console.WriteLine(arreglo[i]);
}
Console.ReadLine();

}


}
}
___________________________________________________________________________________________

multiplicacion de matris
____________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

int[,] a = new int[4, 4];
int[,] b = new int[4, 4];
int[,] c = new int[4,4];

Random objeto = new Random();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

a[i, j] = objeto.Next(20);
}
}

for (int i = 0; i < 4; i++)//i es filas
{
for (int j = 0; j < 4; j++)// j es columna //ve columna
{
Console.Write(a[i, j] + "\t");//para q imprima la matriz

}
Console.WriteLine();//para que de un salto de linea
}
Console.WriteLine("===========================================");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

b[i, j] = objeto.Next(20);
}
}
for (int i = 0; i < 4; i++)//i es filas
{
for (int j = 0; j < 4; j++)// j es columna //ve columna
{
Console.Write(b[i, j] + "\t");//para q imprima la matriz

}
Console.WriteLine();//para que de un salto de linea
}
Console.WriteLine("========================================================");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
c[i,j] = 0;
for (int k = 0; k < 4; k++)
{
c[i,j] = c[i,j] + (a[i,k] * b[k,j]);

}
}
}
for (int i = 0; i < 4; i++)//i es filas
{
for (int j = 0; j < 4; j++)// j es columna //ve columna
{
Console.Write(c[i, j]+"\t");
}
Console.WriteLine();
}
}
}
}

No hay comentarios:

Publicar un comentario