Informática
Apuntes, enlaces e información sobre asignaturas de informática

Ejercicios C#

        string[,] nombres = new string[10,3];
        int n = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void txPos_TextChanged(object sender, EventArgs e)
        {

        }
        private void mostrar()
        {
            listBox1.Items.Clear();
            for (int i = 0; i < 10; i++)
            {
                listBox1.Items.Add((i+1).ToString() + ".- " + nombres[i, 0] + " " + nombres[i, 1] + " " + nombres[i, 2] + " ");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int pos = int.Parse(txPos.Text) - 1;
            if (pos < 10)
            {
                nombres[pos, 0] = txNombre.Text;
                nombres[pos, 1] = txApellido1.Text;
                nombres[pos, 2] = txApellido2.Text;
                txPos.Text = (pos + 2).ToString();
                mostrar();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int pos = int.Parse(txPos.Text) - 1;
            if (pos < 10)
            {
                listBox1.Items.Clear();
                listBox1.Items.Add((pos+1).ToString() + ".- " + nombres[pos, 0] + " " + nombres[pos, 1] + " " + nombres[pos, 2] + " ");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string menor;
            menor = nombres[0, 0];
            for (int i = 0; i < 10; i++)
            {
                if (nombres[i, 0] != null && String.Compare(nombres[i, 0], menor)<0) menor = nombres[i, 0];
            }
            listBox1.Items.Clear();
            listBox1.Items.Add("Menor: " + menor);
        }
        private int veces(string nombre )
    {
        int c = 0;
        for (int i = 0; i < 9; i++)
            if (nombres[i, 0] == nombre) c++;
        return c;
    }

        private void button4_Click(object sender, EventArgs e)
        {
            string repetido;
            repetido = nombres[0, 0];
            for (int i = 0; i < 10; i++)
            {
                if (nombres[i, 0] != null && veces(repetido) < veces(nombres[i, 0])) repetido = nombres[i, 0];
            }
            listBox1.Items.Clear();
            listBox1.Items.Add("Repetido: " + repetido);
        }
        private void clickTorreta(object sender, EventArgs e)
    {
        Button t = (Button)sender; int v;
        v = int.Parse(t.Text);
        if (v > 20) t.Hide();
        else t.Text = (v + 1).ToString();

    }
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            Button torre = new Button();
            Random r= new Random();
            torre.Left = e.X;
            torre.Top = e.Y;
            torre.Name = "torre" + n.ToString();
            torre.Text = r.Next(1, 10).ToString();
            torre.Click += new EventHandler(clickTorreta);
            torre.Parent = this;
        }

09:09 | palimp2 | 0 Comentarios | #

Soluciones ejercicios

    Function ConteoVocal(ByVal cadena As String) As String
        Dim v(5) As Integer, vocales As String = "aeiou", res As String
        cadena = cadena.ToLower
        res = ""
        For i = 0 To cadena.Length - 1
            If vocales.IndexOf(cadena.Substring(i, 1)) >= 0 Then
                v(vocales.IndexOf(cadena.Substring(i, 1))) += 1
            End If
        Next
        For i = 0 To 4
            res = res & vocales(i) & v(i)
        Next
        Return res
    End Function
    Function DiasFestivos(ByVal mes As Integer, ByVal anyo As Integer) As Integer
        Dim f As Date, cont As Integer = 0
        For i = 1 To Date.DaysInMonth(anyo, mes)
            f = Date.Parse(anyo & "/" & mes & "/" & i)
            If f.DayOfWeek = DayOfWeek.Saturday Or f.DayOfWeek = DayOfWeek.Sunday Then
                cont += 1
            End If
        Next
        Return cont
    End Function
    Function EsPrimo(ByVal num As Long) As Boolean
        For i = 2 To Math.Sqrt(num)
            If num Mod i = 0 Then
                Return False
            End If
        Next
        Return True
    End Function
    Function Diagonal(ByVal lado As Integer) As Integer(,)
        Dim d(lado - 1, lado - 1) As Integer
        For i = 0 To lado - 1
            d(i, i) = 1
        Next
        Return d
    End Function
    Function triplicar(ByVal lista As ArrayList) As ArrayList
        Dim res As New ArrayList
        For Each i As Object In lista
            res.Add(i & i & i)
        Next
        Return res
    End Function
    Function ToHashTable(ByVal lista As ArrayList) As Hashtable
        Dim res As New Hashtable
        If lista.Count Mod 2 <> 0 Then lista.Add("")
        For i = 0 To lista.Count - 1 Step 2
            res.Add(lista(i), lista(i + 1))
        Next
        Return res
    End Function
    Function ToArrayList(ByVal tabla As Hashtable) As ArrayList
        Dim res As New ArrayList
        For Each d As DictionaryEntry In tabla
            res.Add(d.Key)
            res.Add(d.Value)
        Next
        Return res
    End Function

11:37 | palimp2 | 0 Comentarios | #

Cuadrado con un for


int ancho, alto;
string cad="";
listBox1.Items.Clear();
ancho = int.Parse(textBox1.Text);
alto = int.Parse(textBox2.Text);
cad = cad.PadLeft(ancho, 'O');
for (int i = 0; i < alto; i++)
listBox1.Items.Add(cad);
listBox1.Items.Add("----");
cad = "";
for (int i = 1; i <= ancho * alto; i++)
{
cad += "O";
if (i % ancho == 0)
{
listBox1.Items.Add(cad);
cad = "";
}
}

09:37 | palimp2 | 1 Comentarios | #

Reservas on line

Nuestra empresa está conectada con organizadores de conciertos. Estos nos ofrecen un número determinado de entradas por concierto que nosotros podemos poner a la venta con un descuento.

En nuestra web el usuario puede ver todos los datos del concierto, así como cuanto vale la entrada. Puede reservas las entradas que quiera del concierto y nos gustaría saber la fecha.

A medida que se acerca la fecha del concierto nosotros podemos cambiar el precio de la entrada -normalmente lo ponemos más caro para premiar a los que reservan antes.

Cuando un usuario reserva le pedimos su dni para que se identifique en la taquilla y su correo electrónico para poder enviarle publicidad.

11:49 | palimp2 | 1 Comentarios | #

Análisis Funcional

Introducción y objetivos
- Por qué se hace este programa, necesidades que cubre y en que mejora la situación actual.

Descripció del programa
- Qué hace la aplicación y como lo hace.

Limitaciones
- Qué queda fuera del alcance de la aplicación

Apartados
- Todos los apartados del programa, explicando su funcionalidad y aportando una idea de como será la interfaz de usuario.

Base de datos
- Esquema de la base de datos relacional.

Documentación
- La documentación que se entregará junto con el programa.

Requerimientos
- Qué necesitamos para poder ejecutar el programa; hardware y software.

Cuaderno de carga
- Como se repartirán las tareas dentro del grupo.

Calendario
- Plazos de entrega de las diferentes partes del proyecto.

11:16 | palimp2 | 1 Comentarios | #

Usar Ajax

function cargarContenido(pagina,objeto){
var contenedor;
contenedor = document.getElementById(objeto);
ajax=nuevoAjax();
ajax.open("GET", pagina,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}

08:49 | palimp2 | 0 Comentarios | #

XMLHTTPREQUEST

function nuevoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

08:47 | palimp2 | 0 Comentarios | #

Ejemplo clases

Public MustInherit Class Productos
    Private pReferencia As String
    Protected pStock As Integer
    Property Referencia() As String
        Get
            Return pReferencia
        End Get
        Set(ByVal value As String)
            pReferencia = value
        End Set
    End Property
    ReadOnly Property Stock() As Integer
        Get
            Return pStock
        End Get
    End Property
    MustOverride Function PonerStock(ByVal cantidad As Integer) As Integer

    MustOverride Function SacarStock(ByVal cantidad As Integer) As Integer
End Class
Public Class Intangibles
    Inherits Productos
    Private pFechaDesde As DateTime
    Private pFechaHasta As DateTime
    Property FechaDesde() As DateTime
        Get
            Return pFechaDesde
        End Get
        Set(ByVal value As DateTime)
            pFechaDesde = value
        End Set
    End Property
    Property FechaHasta() As DateTime
        Get
            Return pFechaHasta
        End Get
        Set(ByVal value As DateTime)
            pFechaHasta = value
        End Set
    End Property
    Sub New(ByVal referencia As String)
        Me.Referencia = referencia
    End Sub
    Public Overrides Function PonerStock(ByVal cantidad As Integer) As Integer
        If cantidad > 0 Then
            Me.pStock += cantidad
            Return Me.Stock
        Else
            Return -1
        End If
    End Function

    Public Overrides Function SacarStock(ByVal cantidad As Integer) As Integer
        If cantidad >= Me.Stock Then
            Me.pStock -= cantidad
            Return Me.Stock
        Else
            Return -1
        End If
    End Function
End Class
Class ropa
    Inherits Productos
    Private pTipo As String
    Private pColores As ArrayList
    Private pTallas As ArrayList
    Property Tipo() As String
        Get
            Return pTipo
        End Get
        Set(ByVal value As String)
            pTipo = value
        End Set
    End Property
    Property Colores(ByVal indice As Integer) As String
        Get
            If indice < pColores.Count Then
                Return pColores(indice)
            End If
            Return Nothing
        End Get
        Set(ByVal value As String)
            If indice < pColores.Count Then
                pColores(indice) = value
            Else
                pColores.Add(value)
            End If

        End Set
    End Property
    Property Tallas(ByVal indice As Integer) As String
        Get
            If indice < ptallas.Count Then
                Return ptallas(indice)
            End If
            Return Nothing
        End Get
        Set(ByVal value As String)
            If indice < pTallas.Count Then
                pTallas(indice) = value
            Else
                pTallas.Add(value)
            End If

        End Set
    End Property
    Sub New(ByVal referencia As String)
        pTallas = New ArrayList
        pColores = New ArrayList

        Me.Referencia = referencia
    End Sub
    Sub New(ByVal referencia As String, ByVal tipo As String)
        pTallas = New ArrayList
        pColores = New ArrayList
        Me.Referencia = referencia
        Me.Tipo = tipo
    End Sub
    Public Overrides Function PonerStock(ByVal cantidad As Integer) As Integer
        If cantidad > 0 Then
            Me.pStock += cantidad
            Return Me.Stock
        Else
            Return -1
        End If

    End Function
    Public Overloads Function PonerStock(ByVal cantidad As Integer, ByVal color As String) As Integer
        If pColores.Contains(color) Then
            Return PonerStock(cantidad)
        Else
            Return -1
        End If
    End Function

    Public Overrides Function SacarStock(ByVal cantidad As Integer) As Integer
        If cantidad >= Me.Stock Then
            Me.pStock -= cantidad
            Return Me.Stock
        Else
            Return -1
        End If

    End Function
    Public Overloads Function SacarStock(ByVal cantidad As Integer, ByVal color As String) As Integer
        If pColores.Contains(color) Then
            Return SacarStock(cantidad)
        Else
            Return -1
        End If
    End Function
    Sub addColores(ByVal ParamArray listacolores() As String)
        For Each Color As String In listacolores
            pColores.Add(Color)
        Next
    End Sub
    Sub addTallas(ByVal ParamArray listatallas() As String)
        For Each Talla As String In listatallas
            pTallas.Add(Talla)
        Next
    End Sub
    Function Hay(ByVal color As String, ByVal talla As String) As Boolean
        Return pColores.Contains(color) And pTallas.Contains(talla)
    End Function
End Class

09:06 | palimp2 | 0 Comentarios | #

Dígito COntrol

http://www.mvp-access.com/softjaen/vb2005/funciones/dc/sjvb05func11.htm

09:06 | palimp2 | 0 Comentarios | #

Ejercicios VB

    Function Mezclar(ByVal cad1 As String, ByVal cad2 As String) As String
        Dim res As String = "", i As Integer
        For i = 0 To Math.Max(cad1.Length, cad2.Length) - 1
            If i < cad1.Length Then res += cad1.Chars(i)
            If i < cad2.Length Then res += cad2.Chars(i)
        Next
        Return res
    End Function
    Function reducir(ByVal cadena As String) As String
        Dim m() As String = cadena.Split(" "), res As String = "", i As Integer

        For i = 0 To m.GetUpperBound(0) Step 2
            res += m(i) + " "
        Next
        Return Trim(res)
    End Function
    Function arbol(ByVal cadena As String) As String
        Dim res As String = "", a As String = "", i As Integer
        For i = cadena.Length - 1 To 0 Step -1
            a = cadena.Chars(i) + a + cadena.Chars(i)
            res += a + vbCrLf
        Next
        Return res
    End Function
    Function viernes(ByVal anyo As Integer, ByVal mes As Integer) As String
        Dim res As String = "", i As Integer, d As DateTime
        For i = 1 To DateTime.DaysInMonth(anyo, mes)
            d = New DateTime(anyo, mes, i)
            If d.DayOfWeek = DayOfWeek.Friday Then
                res &= i & ","
            End If
        Next
        Return res.Substring(0, res.Length - 1)

    End Function
    Function filtrar(ByVal lista As ArrayList, ByVal longitud As Integer) As ArrayList
        Dim nueva As ArrayList, i As Integer

        nueva = lista.Clone
        For i = nueva.Count - 1 To 0 Step -1
            If nueva(i).ToString.Length > longitud Then
                nueva.RemoveAt(i)

            End If
        Next
        Return nueva

    End Function

09:06 | palimp2 | 0 Comentarios | #

Ahorcado

<?
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>El ahorcado</title>
</head>

<body>

<?
$lista[]="luz";
$lista[]="mar";
$lista[]="sol";
$lista[]="rey";
$lista[]="ala";
$lista[]="oso";
$lista[]="tio";
$lista[]="paz";
if (isset($_POST["Nuevo"]))
{
$_SESSION["Jugar"]=1;
$_SESSION["Palabra"]=$lista[rand(0,count($lista)-1)];
$_SESSION["Intentos"]=0;
$_SESSION["Letras"]="";
}
?>

<form name="form1" method="post" action="">
  <input type="submit" name="Nuevo" value="Juego Nuevo">

</form>
<?
if (!empty($_SESSION["Jugar"]))
{
//echo $_SESSION["Palabra"]."<br>";
if (!empty($_POST["letra"]) && strpos($_SESSION["Letras"],$_POST["letra"])===false)
{
	$_SESSION["Letras"].=$_POST["letra"];
	if (strpos($_SESSION["Palabra"],$_POST["letra"])===false)
		{
		echo "La letra ".$_POST["letra"]." no está en la palabra.<br>";
		$_SESSION["Intentos"]++;
		}
}
for ($i=0;$i<strlen($_SESSION["Letras"]);$i++)
 echo $_SESSION["Letras"][$i]."  ";
 echo "<br>";
$acierto=true;
for ($i=0;$i<strlen($_SESSION["Palabra"]);$i++)
if (strpos($_SESSION["Letras"],$_SESSION["Palabra"][$i])===false)
	{echo "_ ";$acierto=false;}
else
 echo $_SESSION["Palabra"][$i]." ";
echo "<br>";
if ($_SESSION["Intentos"]<6 && !$acierto)
{
?>

<form name="form2" method="post" action="">
  <input name="letra" type="text" maxlength="1">

  <input type="submit" name="Submit" value="Probar">
</form>
<?
}
else
	if ($acierto)
		echo "¡¡HAS GANADO!! ¡¡ENHORABUENA!!<br>";
	else
		echo "Has perdido. La palabra era ".$_SESSION["Palabra"]."<br>";
?>

<img src="./images/ahorcado0<? echo $_SESSION["Intentos"] ?>.gif">
<?
}

?>
<p>&nbsp;</p>
</body>
</html>

09:46 | palimp2 | 0 Comentarios | #

Anagrama

  Function anagrama(ByVal cad As String) As String()
        Dim i As Integer, tam As Long = 1, j As Integer
        Dim letra As String, resto As String
        For i = 1 To cad.Length
            tam *= i
        Next
        Dim anagramas(tam - 1) As String, res() As String
        If cad.Length = 1 Then
            anagramas(0) = cad
            Return anagramas
        End If
        tam = 0
        For i = 0 To cad.Length - 1
            letra = cad.Substring(i, 1)
            If i = 0 Then
                resto = cad.Substring(1)
            Else
                resto = cad.Substring(0, i) + cad.Substring(i + 1)
            End If
            res = anagrama(resto)
            For j = 0 To res.GetUpperBound(0)
                anagramas(tam) = letra + res(j)
                tam += 1
            Next
        Next
        Return anagramas
    End Function

13:19 | palimp2 | 0 Comentarios | #

Palabras repetidas

Function repetidas(ByVal cad As String) As String()
    Dim palabras As String() = cad.Split(" ")
    Dim i As Integer, res As String = ""
    For i = 0 To palabras.GetUpperBound(0)
       If Array.IndexOf(palabras, palabras(i), i + 1) <> -1 
       And Array.IndexOf(res.Split(" "), palabras(i)) = -1 Then
           res = res + palabras(i) + " "
       End If
    Next
    Return res.Trim().Split(" ")
End Function

13:18 | palimp2 | 0 Comentarios | #

Juego de la vida

    class Program
    {
        static void Main(string[] args)
        {
            String res;
            int[,] tablero = new int[,]{
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
            do
            {
                Mostrar(tablero);
                tablero = tic(tablero);
                res = Console.ReadLine();
            } while (res != "S");

        }
        static int[,] tic(int[,] tablero)
        {
            int nc;
            int[,] Siguiente = new int[tablero.GetLength(0), tablero.GetLength(1)];
            for (int i=0;i<=tablero.GetUpperBound(0);i++)
                for (int j = 0; j <= tablero.GetUpperBound(1); j++)
                {
                    nc=NumCelulas(tablero,i,j);
                    if ((tablero[i, j] == 0 && nc == 3)||(tablero[i, j] == 1 && nc >= 2 && nc <= 3))
                        Siguiente[i, j] = 1;
                    else
                        Siguiente[i, j] = 0;
                    
                }
            return Siguiente;
        }
        static int NumCelulas(int[,] tablero, int fil, int col)
        {
            int Suma=0;
            for (int i = fil - 1; i <= fil + 1; i++)
                for (int j = col - 1; j <= col + 1; j++)
                    if ((i != fil || j != col) && i >= 0 && j >= 0 && i <= tablero.GetUpperBound(0) && j <= tablero.GetUpperBound(1))
                        Suma += tablero[i, j];
            return Suma;
        }
        static void Mostrar(int[,] tablero)
        {
            for (int i = 0; i <= tablero.GetUpperBound(0); i++)
            {

                for (int j = 0; j <= tablero.GetUpperBound(1); j++)
                {
                    if (tablero[i, j] == 1) Console.Write("#");
                    else Console.Write(" ");
                }
                Console.WriteLine("");
            }

        }

    }

12:05 | palimp2 | 0 Comentarios | #

Funciones cadena

 Function TrimInt(ByVal cad As String) As String
        Do While cad.IndexOf("  ") <> -1
            cad = cad.Replace("  ", " ")
        Loop
        Return cad
    End Function
    Function EliminarCar(ByVal cad As String, ByVal liscar As String) As String
        Dim i As Integer
        For i = 0 To liscar.Length - 1
            cad = cad.Replace(liscar.Chars(i), "")
        Next
        Return cad
    End Function
    Function Invertir(ByVal cad As String) As String
        Dim i As Integer, res As String = ""
        For i = cad.Length - 1 To 0 Step -1
            res = res + cad.Chars(i)
        Next
        Return res
    End Function
    Function capicua(ByVal cad As String) As Boolean
        cad = EliminarCar(cad, " ,'.")
        If cad.ToUpper = Invertir(cad).ToUpper Then
            Return True
        Else
            Return False

        End If
    End Function

09:21 | palimp2 | 0 Comentarios | #

Inicializar arrays

            int[,] tablero = new int[,]{
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

11:43 | palimp2 | 0 Comentarios | #

Código

En esta carpeta encontraréis ejemplos de PHP

http://www.box.net/public/unxj52m8fg

09:53 | palimp2 | 0 Comentarios | #

Ordenacion insercion modular

for (int j = 0; j < Elementos.Length - 1; j++)
            {
                posIs = j / Elementos.GetLength(1);
                posJs = j % Elementos.GetLength(1);
                for (int i = j; i < Elementos.Length - 1; i++)
                {
                    posI = i / Elementos.GetLength(1);
                    posJ = i % Elementos.GetLength(1);
                    if (Elementos[posI, posJ] < Elementos[posIs, posJs])
                    {
                        posIs = posI;
                        posJs = posJ;
                    }

                }
                posI = j / Elementos.GetLength(1);
                posJ = j % Elementos.GetLength(1);
                temp = Elementos[posI, posJ];
                Elementos[posI, posJ] = Elementos[posIs, posJs];
                Elementos[posIs, posJs] = temp;
                
            }

11:45 | palimp2 | 0 Comentarios | #

Ordenacion burbuja modular

            for (int j = 0; j < Elementos.Length - 1; j++)
             for (int i = 0; i < Elementos.Length - 1; i++)
            {
                posI = i / Elementos.GetLength(1);
                posJ = i % Elementos.GetLength(1);
                posIs = (i+1) / Elementos.GetLength(1);
                posJs = (i+1) % Elementos.GetLength(1);
                if (Elementos[posI, posJ] > Elementos[posIs, posJs])
                {
                    temp = Elementos[posI, posJ];
                    Elementos[posI, posJ] = Elementos[posIs, posJs];
                    Elementos[posIs, posJs] = temp;
                }
                
            }

11:44 | palimp2 | 0 Comentarios | #

Duplicar Array

int[] a, b;
int n;
Console.WriteLine("Elementos?");
n = int.Parse(Console.ReadLine());
a = new int[n];
for (int i = 0; i < n; i++)
{
Console.WriteLine("Elemento " + (i + 1));
a[i] = int.Parse(Console.ReadLine());
}
b = new int[n * 2];
Array.Copy(a, b, n);
Array.Copy(a, 0, b, n, n);
foreach (int i in b)
Console.WriteLine(i);


Console.ReadLine();

12:31 | palimp2 | 1 Comentarios | #




		
 

Archivos

<Diciembre 2008
Lu Ma Mi Ju Vi Sa Do
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Documentos


Bloxus

Bloxus

© 2002 palimp2