miércoles, 11 de diciembre de 2013

NUMERO MAYOR DE LA MATRIZ

NUMERO MAYOR DE UNA MATRIZ DE 3 X 3


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace MAYORDEUNAMATRIZ

{

    class Program

    {

        static void Main(string[] args)

        {

            int[,] a, b, c;

            int x, y, w, z, e, f,MAYOR;

            string aux;

            a = new int[3, 3];

            b = new int[3, 3];

            c = new int[3, 3];

            x = 5;

            for (e = 0; e < 3; e++)

            {

                f = 0; y = 5;

                while (f < 3)

                {

                    Console.SetCursorPosition(y, x);

                    aux = Console.ReadLine();

                    a[f, e] = int.Parse(aux);

                    f++;

                    y = y + 10;

                }

                x = x + 5;

            }

 

// OJO, AQUÍ SE OBTIENE EL NUMERO MAYOR DE LA MATRIZ

 

            MAYOR = 0;

            for (e = 0; e < 3; e++)

            {

                f = 0; y = 5;

                while (f < 3)

                {

                    if (MAYOR < a[f, e])

                    {

                        MAYOR = a[f, e];

                    }

                    f++;

                }

                x = x + 5;

            }

            Console.SetCursorPosition(50, 5);

            Console.Write(MAYOR);

            Console.ReadKey();

        }

    }

}

domingo, 8 de diciembre de 2013

MULTIPLICACION DE MATRICES DE 3 X 3

LLENAR 2 MATRICES DESDE TECLADO, MULTIPLICARLAS Y EL RESULTADO GUARDARLO EN UNA TERCER MATRIZ.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication15

{

    class Program

    {

        static void Main(string[] args)

        {

            int[,] a, b, c;

            int x, y,w, z, e, f;

            string aux;

            a = new int[3, 3];

            b = new int[3, 3];

            c = new int[3, 3];

            x = 5;

            for (e = 0; e < 3; e++)

            {

                f = 0; y = 5;

                while (f < 3)

                {

                    Console.SetCursorPosition(y,x);

                    aux = Console.ReadLine();

                    a[f,e] = int.Parse(aux);

                    f++;

                    y = y + 10;

                }

                x = x + 5;

            }

            x = 5;

            for (e = 0; e < 3; e++)

            {

                f = 0; y = 45;

                while (f < 3)

                {

                    Console.SetCursorPosition(y, x);

                    aux = Console.ReadLine();

                    b[f, e] = int.Parse(aux);

                    f++;

                    y = y + 10;

                }

                x = x + 5;

            }

            //MULTIPLICACION DE LAS 2 MATRICES ANTERIORES

            x = 30;
            for (z = 0; z < 3; z++)
            {         
                y = 0; f = 25;
                while (y < 3)
                {
                     w = 0;
                    for (e = 0; e < 3; e++)
                    {
                        w = w + a[e, z] * b[y, e];
                    }
                    c[y, z] = w;
                    Console.SetCursorPosition(f,x);
                    Console.WriteLine(c[y,z]);
                                        y++;

                    f = f + 10;

                }

                x = x + 5;

            }

            Console.ReadKey();

        }

    }

}

martes, 26 de noviembre de 2013

SUMATORIA DE 2 MATRICES DE 3X3

LLENADO DE 2 MATRICES DE 3X3 Y CON EL RESULTADO LLENAR LA TERCER MATRIZ.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace MATRIZ

{

    class Program

    {

        static void Main(string[] args)

        {

            int[,] a,d,e;

            int b, c,x,y,w;

            string aux;

            a = new int[3, 3];

     d = new int[3, 3];

     e = new int[3, 3];

 

            Console.SetCursorPosition(18, 3);

            Console.Write("A");

Console.SetCursorPosition(38, 3);

            Console.Write("D");

 

            x = 5;

            for (b = 0; b < 3; b++)

            {

                c = 0;

                y = 12;w=35;

                while (c < 3)

                {

                    Console.SetCursorPosition(y, x);

                    aux = Console.ReadLine();

                    a[c, b] = int.Parse(aux);

Console.SetCursorPosition(w, x);

                    aux = Console.ReadLine();

                    d[c, b] = int.Parse(aux);

w=w+5;

                    y = y + 5;

                    e[c,b]=a[c,b]+d[c,b];

                    c++;

                }

                x = x + 2;

            }

            Console.ReadKey();

             Console.SetCursorPosition(28, 15);

            Console.Write("E");

x = 17;

            for (b = 0; b < 3; b++)

            {

                c = 0;

                w=25;

                while (c < 3)

                {

                    Console.SetCursorPosition(w, x);

                    Console.Write(e[c, b]);

w=w+5;

                    c++;

                }

                x = x + 2;

            }

            Console.ReadKey();

 

        }

    }

}

LLENAR UNA MATRIZ DE 3X3

LLENADO DE LA MATRIZ   "A"   DE 3X3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace MATRIZ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] a;
            int b, c,x,y;
            string aux;
            a = new int[3, 3];
 
            Console.SetCursorPosition(18, 3);
            Console.Write("A");
            x = 5;
            for (b = 0; b < 3; b++)
            {
                c = 0;
                y = 12;
                while (c < 3)
                {
                    Console.SetCursorPosition(y, x);
                    aux = Console.ReadLine();
                    a[c, b] = int.Parse(aux);
                    y = y + 5;
                    c++;
                }
                x = x + 2;
            }
            Console.ReadKey();
        }
    }
}

MATRIZ

Arreglos bidimensionales (Matrices)


Una matriz es una estructura de datos que permite almacenar un CONJUNTO de datos del MISMO tipo.

Con un único nombre se define la matriz y por medio de DOS subíndices hacemos referencia a cada elemento de la misma (componente).
En este ejemplo almacenamos valores enteros. Todos los elementos de la matriz deben ser del mismo tipo (int, float, string etc.)
Las filas y columnas comienzan a numerarse a partir de cero, similar a los vectores.
Para definir una matriz debemos disponer una coma dentro de los corchetes:
 
         int[,] mat;
 
De esta forma el compilador de C# puede diferenciar los vectores de las matrices.
 
Para crear la matriz, es decir hacer la reserva de espacio de todas sus componentes debemos utilizar el operador new y mediante dos subíndices indicamos la cantidad de filas y columnas que tendrá la matriz:
 
            mat=new int[3,5];
 
Luego debemos pasar a cargar sus 15 componentes (cada fila almacena 5 componentes y tenemos 3 filas)
 
Siempre que accedemos a una posición de la matriz debemos disponer dos subíndices que hagan referencia a la fila y columna mat[f,c]):
 
            for(int f = 0;f < 3;f++) 
            {
                for(int c = 0;c < 5;c++)
                {
                    Console.Write("Ingrese componente:");
                    string linea;
                    linea = Console.ReadLine();
                    mat[f,c]=int.Parse(linea);
                }
            }
Para imprimir la matriz de forma similar utilizamos dos for para acceder a cada elemento de la matriz:
 
            for(int f = 0;f < 3;f++) 
            {
                for(int c = 0;c < 5;c++) 
                {
                    Console.Write(mat[f,c]+" ");
                }
                Console.WriteLine();
            }
 

 

domingo, 24 de noviembre de 2013

MENU CON VECTOR Y ORDENAMIENTO

MENU CON LLENADO DE UN VECTOR Y SU ORDENAMIENTO DE MENOR A MAYOR

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text; 

namespace VECTORES

{

    class Program

    {

        static void Main(string[] args)

        {

            int a, b, c;

            double [] d,e,f;

             string aux;

             d = new double[5];

             e = new double[5];

             f = new double[5];

             do

             {

                 Console.Clear();

                 Console.SetCursorPosition(19, 3);

                 Console.Write("M  E  N  U");

                 Console.SetCursorPosition(10, 5);

                 Console.Write("1.- LLENAR VECTOR");

   Console.SetCursorPosition(10, 6);

                 Console.Write("2.- ORDENAMIENTO DEL VECTOR ANTERIOR DE MENOR A MAYOR");

                 Console.SetCursorPosition(10, 7);

                 Console.Write("3.- SALIR  ");

                 Console.SetCursorPosition(10, 9);

                 Console.Write("QUE OPCION DESEAS  ");

                 aux = Console.ReadLine();

                 a = int.Parse(aux);

                 Console.Clear();

                 switch (a)

                 {

                     case 1:

                         {

                            

                             Console.SetCursorPosition(10, 6);

                             Console.Write("LLENADO DEL VECTOR");

                             Console.SetCursorPosition(10, 8);

                             Console.Write("**********");

                             Console.SetCursorPosition(10, 9);

                             Console.Write("*        *");

                             Console.SetCursorPosition(10, 10);

                             Console.Write("**********");

                             Console.SetCursorPosition(10, 11);

                             Console.Write("*        *");

                             Console.SetCursorPosition(10, 12);

                             Console.Write("**********");

                             Console.SetCursorPosition(10, 13);

                             Console.Write("*        *");

                             Console.SetCursorPosition(10, 14);

                             Console.Write("**********");

                             Console.SetCursorPosition(10, 15);

                             Console.Write("*        *");

                             Console.SetCursorPosition(10, 16);

                             Console.Write("**********");

                             Console.SetCursorPosition(10, 17);

                             Console.Write("*        *");

                             Console.SetCursorPosition(10, 18);

                             Console.Write("**********");

                             b = 9;

                             for (c = 0; c < 5; c++)

                             {

                                 Console.SetCursorPosition(3, b);

                                 Console.Write("d[ " + c + " ]");

                                 Console.SetCursorPosition(12, b);

                                 aux = Console.ReadLine();

                                 d[c] = int.Parse(aux);

                                

                                 b = b + 2;

                             }

                             Console.ReadKey();

                             break;

                         }

                     

                     case 2:

                          Console.SetCursorPosition(10, 6);

                              Console.Write("VECTOR D");

                              Console.SetCursorPosition(10, 8);

                              Console.Write("**********");

                              Console.SetCursorPosition(10, 9);

                              Console.Write("*        *");

                              Console.SetCursorPosition(10, 10);

                              Console.Write("**********");

                              Console.SetCursorPosition(10, 11);

                              Console.Write("*        *");

                              Console.SetCursorPosition(10, 12);

                              Console.Write("**********");

                              Console.SetCursorPosition(10, 13);

                              Console.Write("*        *");

                              Console.SetCursorPosition(10, 14);

                              Console.Write("**********");

                              Console.SetCursorPosition(10, 15);

                              Console.Write("*        *");

                              Console.SetCursorPosition(10, 16);

                              Console.Write("**********");

                              Console.SetCursorPosition(10, 17);

                              Console.Write("*        *");

                              Console.SetCursorPosition(10, 18);

                              Console.Write("**********");

 

                              Console.SetCursorPosition(37, 6);

                              Console.Write("VECTOR E ORDENADO");

                              Console.SetCursorPosition(40, 8);

                              Console.Write("**********");

                              Console.SetCursorPosition(40, 9);

                              Console.Write("*        *");

                              Console.SetCursorPosition(40, 10);

                              Console.Write("**********");

                              Console.SetCursorPosition(40, 11);

                              Console.Write("*        *");

                              Console.SetCursorPosition(40, 12);

                              Console.Write("**********");

                              Console.SetCursorPosition(40, 13);

                              Console.Write("*        *");

                              Console.SetCursorPosition(40, 14);

                              Console.Write("**********");

                              Console.SetCursorPosition(40, 15);

                              Console.Write("*        *");

                              Console.SetCursorPosition(40, 16);

                              Console.Write("**********");

                              Console.SetCursorPosition(40, 17);

                              Console.Write("*        *");

                              Console.SetCursorPosition(40, 18);

                              Console.Write("**********");

                          b = 9;

                             for (c = 0; c < 5; c++)

                             {

                                 Console.SetCursorPosition(3, b);

                                 Console.Write("d[ " + c + " ]");

                                 Console.SetCursorPosition(12, b);

                                 Console.Write(d[c]);

                                 b = b + 2;

                             }

                             for (c = 0; c < 5; c++)

                             {

                                 e[c] = d[c];

                             }

                             double x;

                             for (a = 0; a < 4; a++)

                             {

                                 for (b = a + 1; b < 5; b++)

                                 {

                                     if (e[a] > e[b])

                                     {

                                         x = e[a];

                                         e[a] = e[b];

                                         e[b] = x;

                                     }

                                 }

                             }

                         b = 9;

                              for (c = 0; c < 5; c++)

                              {

                                 Console.SetCursorPosition(30, b);

                                  Console.Write("e[ " + c + " ]");

                                  Console.SetCursorPosition(43, b);

                                  Console.Write(e[c]);

                                  b = b + 2;

                              }

                              Console.ReadKey();

                          break;

                     case 3:

                          break;

                     default:

                         Console.SetCursorPosition(23, 8);

                                  Console.Write("ENTIENDE SOLO SON 4 OPCIONES");

                                  Console.ReadKey();

                          break;

 

                 }

 

 

             }

             while (a != 3);

 

        }

    }

}