jueves, 11 de octubre de 2012

paulo escobar Fotos

obtener el largo y ancho de una matriz en java


Para declarar un matriz

tipo[][] nombreMatriz = new tipo[numerofilas][numerocolumnas];

int[][] mat = new int[10][20];
int numfilas = mat.length; //Determina el número de las filas
int numcolumnas = mat[0].length; //determina el número de las columnas

Metodo de ordenación para matrices en c sharp

Este es un método(sub-programa)  que no retorna un valor por que es tipo void
pero hace un proceso interno que es ordenar una matriz
la matriz entra como parametro al metodo y el algoritmo se encarga de hacer el proceso de ordenación mediante dos ciclos for.
  public void ordenarMatriz(int[,] A)
        {
            int posmay ;
            int posmax ;
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    posmax = x;
                    posmay = y;
                    for (int i = 0; i < 3; i++)
                    {

                        for (int j = 0; j < 3; j++)
                        {

                            if (A[posmax,posmay] < A[i, j])
                            {
                                posmax = i;
                                posmay = j;
                                aux = A[x, y];
                                A[x, y] = A[posmax, posmay];
                                A[posmax, posmay] = aux;

                            }
                        }

                    }
                }
        }

// creado por Paulo Andres Escobar

algoritmo que convierte un numero decimal a octal


 private void button1_Click(object sender, EventArgs e)
    {
            string res = "";
            int y = int.Parse(textBox1.Text);
            while (y > 0)
            {
                res = (y % 8).ToString() + res;
                y = y / 8;
            }
            textBox1.Text = res;
            res = "";
         
  }

decimal a hexadecimal en c sharp


 private void button3_Click(object sender, EventArgs e)
        {
            string res = "";
            string ress = "";
            int residuo;
            int y = int.Parse(textBox1.Text);
            while (y >0)
            {
                residuo = y % 16;
                y = y / 16;
                if (residuo > 9)
                {
                    switch (residuo)
                    {
                        case 10:
                            res = "A";
                            break;
                        case 11:
                            res = "B";
                            break;
                        case 12:
                            res = "C";
                            break;
                        case 13:
                            res = "D";
                            break;
                        case 14:
                            res = "E";
                            break;
                        case 15:
                            res = "F";
                            break;

                    }

                }
                else
                    res = residuo.ToString();
                ress = res + ress;
             
            }
            textBox1.Text = ress;
            res = "";
         
        }

/// creado por paulo andres escobar

miércoles, 10 de octubre de 2012

codigo para convertir de hexadecimal a decimal en c sharp


//este algoritmo es implementado en c sharp

        private void BotonConvertir_Click(object sender, EventArgs e)
        {
            string numero = textBox1.Text;
            int y = numero.Length;
            double suma = 0;
            int x;

            for (int i = 0; i < y; i++)
            {
                string n = numero.Substring(i,1);
  //en esta instruccion tomamos el string que es la cadena de caracteres y sacamos una pequeña porcion con esta instruccion, a partir de una posicion especificada por  i , el 1 significa la cantidad de letras que va a tomar apartir de la posicion dada.         
                    switch (n)
                    {
                        case "A":
                         
                                x= 10;
                                suma =  (Math.Pow(16, i) * x)+suma;
                                break;
                         
                        case "B":
                         
                                x=11;
                                suma =   (Math.Pow(16, i) * x)+suma;
                                break;
                         
                        case "C":
                         
                                x=12;
                                suma =(Math.Pow(16, i) * x)+suma;
                                break;
                         
                        case"D" :
                         
                            x=13;
                            suma = (Math.Pow(16, i) * x)+suma;
                            break;
                         
                        case "E":
                         
                                x=14;
                                suma =  (Math.Pow(16, i) * x)+suma;
                                break;
                         
                        case"F" :
                         
                                x=15;
                                suma = (Math.Pow(16, i) * x)+suma;
                                break;
                         
                        default:
                         
                                 x = int.Parse(n);
                                suma = (Math.Pow(16, i) * x)+suma;
                                break;

                    }


             
               }


                  textBox1.Text = suma.ToString();
            }
       
//codigo por paulo escobar

viernes, 5 de octubre de 2012

convertir de octal a decimal


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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
         
            string numero = textBox1.Text;
            int y = numero.Length;
            int Octal = int.Parse(numero);
            double sumador = 0;
            int x=y;
            for (int i = 0; i < y; i++)
            {
             
                int ultimo_numero = Octal % 10;
                Octal = Octal / 10;
                if (ultimo_numero == 9)
                {
                    i = y + 1;
                    MessageBox.Show("numero no es octal");
                 
                }
                else
                {
                    sumador = sumador + (Math.Pow(8, i) * ultimo_numero);

                }
                 x = i;
           
            }
            if (x==y-1)
                textBox2.Text = sumador.ToString();
            else
                textBox2.Text = "intenta de nuevo";

        }
    }
}

//por paulo andres escobar

convertir de decimal a binario en c sharp


        private void button1_Click(object sender, EventArgs e)
        {
            int y = int.Parse(textBox1.Text);
                while (y >0)
                {
                    res = (y % 2).ToString()+res ;
                    y = y / 2;
                }
                textBox1.Text = res;
                res = "";
        }

algoritmo para convertir de Binario a Decimal

este es un algoritmo clasico.
este algoritmo convierte de binario a decimal

namespace Convertidor_de__Binario_a_Decimal
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string numero = textBox1.Text;
            int y = numero.Length;
            int binario = int.Parse(numero);
            double sumador = 0;
           
            for (int i = 0; i < y; i++)
            {
                int ultimo_numero= binario%10;
                binario = binario/10;
                if (ultimo_numero == 0 || ultimo_numero == 1)
                {
                    sumador = sumador + (Math.Pow(2, i) * ultimo_numero);
                }
                else
                {
                    MessageBox.Show("numero no binario");
                    i = y + 1;  // esto es para que controle el ciclo y no entre de nuevo
                }
            }
            textBox1.Text = sumador.ToString();
        }
    }

}

// por paulo andres escobar




miércoles, 3 de octubre de 2012

algoritmos para encontrar la traspuesta de una matriz en c sharp c#

//este algoritmos sirve tanto en java como en c sharp
int i,j;
int temp;
    For (int i=0; i<n; i++)
    {
        For (int j = i+1;j<n;j++)
        {
            temp:=A[i,j];
            A[i,j]:=A[j,i];
            A[j,i]:=temp;

         }
     }
//una transpuesta de una matriz

martes, 2 de octubre de 2012

usar la funcion random c#

este algoritmo genera un numero randomico osea al azar,
algoritmo de mucho uso en juegos.

namespace NumeroRandomico
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(NumeroRandomico(0, 100000).ToString());
        }
        static int NumeroRandomico(int numero1, int numero2)
        {
            Random random = new Random();
            return random.Next(numero1, numero2);
        }
    }
}

programación orientada objetos trabajo con matrices


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string r = "s";
            Matriz matriz = new Matriz();
            matriz.IniciarPrograma();
            while (r == "s")
            {
                matriz.Menu();
                if (matriz.resp == "1")
                {
                    matriz.llenar_matrices_para_multiplicar();
                    matriz.Multiplicar();

                }
                if (matriz.resp == "2")
                {
                    matriz.llenarmatriz_Para_Ordenar();
                    matriz.ordenarMatriz(matriz.matriz1);
                    matriz.print();
                }


            }
           
        }
    }
    class Matriz
    {
        public string  resp;
       
        public int aux;
        public int respuesta=0;
        public int r,c,r2,c2;
        public int[,] matriz1;
        public int[,] matriz2;
        public int[,] matrizRespuestas = new int[3, 3];
        public void Menu()
        {
            Console.WriteLine("[1]multiplicar [2]ordenar");
            resp = Console.ReadLine();
           

        }
        public void llenarmatriz_Para_Ordenar()
        {
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    Console.WriteLine("matriz 1 ingrese un valor en la posicion :{0},{1} ", i, j);
                    matriz1[i, j] = int.Parse(Console.ReadLine());

                }
            }

        }
        public void IniciarPrograma()
        {
            Console.WriteLine("----------Bienvenido a la matriz---------------");
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("-----------------------------------------------");
            r = 3;
            c = 3;
            matriz1 = new int[3, 3];
            r2 = 3;
            c2 = 3;
            matriz2 = new int[r2, c2];
        }
        public void llenar_matrices_para_multiplicar()
        {
            if (c == r2)
            {
               
           
           

            // COMIENZA CICLO PARA LLENAR LA PRIMERA MATRIZ
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    Console.WriteLine("matriz 1 ingrese un valor en la posicion :{0},{1} ", i, j);
                    matriz1[i, j] = int.Parse(Console.ReadLine());

                }
            }
            //COMIENZA CICLO PARA LLENAR LA SEGUNDA MATRIZ
            Console.WriteLine("LISTO!! AHORA INGRESE LOS VALORES DE LA SEGUNDA MATRIZ");
            for (int i = 0; i < r2; i++)
            {
                for (int j = 0; j < c2; j++)
                {
                    Console.WriteLine("matriz 2 ingrese un valor en la posicion :{0},{1} ", i, j);
                    matriz2[i, j] = int.Parse(Console.ReadLine());

                }
            }


            }
            else
            {
                Console.WriteLine("estas matrices no se pueden multiplicar");
            }
        }
        public void Multiplicar()
        {
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c2; j++)
                {
                    for (int k = 0; k < c; k++)
                    {
                        respuesta += matriz1[i, k] * matriz2[k, j];
                    }
                    matrizRespuestas[i, j] = respuesta;
                    respuesta = 0;
                }

            }
            Console.WriteLine("!!!!!!LA RESPUESTA ES !!!!!!");
            string igual = "";
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c2; j++)
                {
                    igual = igual + (matrizRespuestas[i, j].ToString() + " ");
                }
                Console.WriteLine("[" + igual + "]\n");
                igual = "";

            }


        }
        public void print()
        {
            string igual = "";
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c2; j++)
                {
                    igual = igual + (matriz1[i, j].ToString() + " ");
                }
                Console.WriteLine("[" + igual + "]\n");
                igual = "";

            }
        }

        public void ordenarMatriz(int[,] A)
        {
            int posmay ;
            int posmax ;
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    posmax = x;
                    posmay = y;
//matriz a comparar***********************************************************
                    for (int i = 0; i < 3; i++)
                    {

                        for (int j = 0; j < 3; j++)
                        {

                            if (A[posmax,posmay] < A[i, j])
                            {
                                posmax = i;
                                posmay = j;
                                aux = A[x, y];
                                A[x, y] = A[posmax, posmay];
                                A[posmax, posmay] = aux;

                            }
                        }

                    }

///************************fin del ciclo de la matriz a comparar********************
                }
        }

            
        }
    }
}