domingo, 20 de agosto de 2017

EJERCICIOS PROPUESTOS

PROFESOR:

              - Mg. Sanchez Ticona Robert Jerry.

INTEGRANTES: 

             -Ramos Llanos Leslie Tatiana.
             -Vargas Reyes Axel Artemio.

EJERCICIO #1:

ELABORAR UN PROGRAMA QUE PERMITA JUGAR TRES EN RAYA, Y QUE ESTE PROGRAMA SEA DE DOS JUGADORES.

1.-PSEINT :

1.1.-CODIFICACIÓN :

Proceso Trabajo
    Dimension Tab1[3,3];
    Dimension Tab2[3,3];
    Para i<-1 Hasta 3 Hacer
        Para j<-1 Hasta 3 Hacer
            Tab1[i,j]<-0;
            Tab2[i,j]<-" ";
        FinPara
    FinPara
    TurnoJugador1<-Verdadero;
    Terminado<-Falso;
    Ganador<-Falso;
    CantTurnos<-0;
   
    Mientras ~ Terminado hacer
       
        Borrar Pantalla;
        Escribir " ";
        Escribir "      ||     ||     ";
        Escribir "   ",Tab2[1,1],"  ||  ",Tab2[1,2],"  ||  ",Tab2[1,3];
        Escribir "     1||    2||    3";
        Escribir " =====++=====++======";
        Escribir "      ||     ||     ";
        Escribir "   ",Tab2[2,1],"  ||  ",Tab2[2,2],"  ||  ",Tab2[2,3];
        Escribir "     4||    5||    6";
        Escribir " =====++=====++======";
        Escribir "      ||     ||     ";
        Escribir "   ",Tab2[3,1],"  ||  ",Tab2[3,2],"  ||  ",Tab2[3,3];
        Escribir "     7||    8||    9";
        Escribir " ";
       
        Si ~ Ganador y CantTurnos<9 Entonces
           
            Si TurnoJugador1 Entonces
                Ficha<-'O'; Valor<- 1; Objetivo<-1;
                Escribir "Turno del jugador 1 (X)";
            Sino
                Ficha<-'X'; Valor<- 2; Objetivo<-8;
                Escribir "Turno del jugador 2 (O)";
            FinSi
           
            Escribir "Ingrese la Posición (1-9):";
           
            Repetir
                Leer Pos;
                Si Pos<1 o Pos>9 Entonces
                    Escribir "Posición incorrecta, ingrese nuevamente: ";
                    Pos<-99;
                Sino
                    i<-trunc((Pos-1)/3)+1;
                    j<-((Pos-1) MOD 3)+1;
                    Si Tab1[i,j]<>0 Entonces
                        pos<-99;
                        Escribir "Posición incorrecta, ingrese nuevamente: ";
                    FinSi
                FinSi
            Hasta Que Pos<>99
                                              
            CantTurnos<-CantTurnos+1;
            Tab1[i,j]<-Valor;
            Tab2[i,j]<-Ficha;
           
                                               aux_d1<-1; aux_d2<-1;
            Para i<-1 hasta 3 hacer
                aux_i<-1; aux_j<-1;
                aux_d1<-aux_d1*Tab1[i,i];
                aux_d2<-aux_d2*Tab1[i,4-i];
                Para j<-1 hasta 3 hacer
                    aux_i<-aux_i*Tab1[i,j];
                    aux_j<-aux_j*Tab1[j,i];
                FinPara
                Si aux_i=Objetivo o aux_j=Objetivo Entonces
                    Ganador<-Verdadero;
                FinSi
            FinPara
            Si aux_d1=Objetivo o aux_d2=Objetivo Entonces
                Ganador<-Verdadero;
            Sino
                TurnoJugador1 <- ~ TurnoJugador1;
            FinSi
           
        Sino
           
            Si Ganador Entonces
                Escribir "Ganador: ";
                Si TurnoJugador1 Entonces
                    Escribir "Jugador 1!";
                Sino
                    Escribir "Jugador 2!";
                FinSi
            Sino
                Escribir "Empate!";
            FinSi
            Terminado<-Verdadero;
           
        FinSi
       
    FinMientras

FinProceso

1.2.-COMPILACIÓN :



2.-VISUAL STUDIO :

2.1.-CODIFICACIÓN :

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

namespace Tes_en_raya
{
    class Program
    {
        static void Main(string[] args)
        {
            double aux_d1, aux_d2, aux_i, aux_j, cantturnos;
            string ficha;
            bool ganador;
            int i = 0, j = 0;
            double objetivo;
            int pos;
            bool terminado, turnojugador1;
            double valor;
            double[,] tab1 = new double[3, 3];
            string[,] tab2 = new string[3, 3];
            for (i = 1; i <= 3; i++)
            {
                for (j = 1; j <= 3; j++)
                {
                    tab1[i - 1, j - 1] = 0;
                    tab2[i - 1, j - 1] = " ";
                }
            }
            turnojugador1 = true;
            terminado = false;
            ganador = false;
            cantturnos = 0;
            while (!terminado)
            {
                Console.Clear();
                Console.WriteLine(" ");
                Console.WriteLine("      ||     ||     ");
                Console.WriteLine("   " + tab2[0, 0] + "  ||  " + tab2[0, 1] + "  ||  " + tab2[0, 2]);
                Console.WriteLine("     1||    2||    3");
                Console.WriteLine(" =====++=====++======");
                Console.WriteLine("      ||     ||     ");
                Console.WriteLine("   " + tab2[1, 0] + "  ||  " + tab2[1, 1] + "  ||  " + tab2[1, 2]);
                Console.WriteLine("     4||    5||    6");
                Console.WriteLine(" =====++=====++======");
                Console.WriteLine("      ||     ||     ");
                Console.WriteLine("   " + tab2[2, 0] + "  ||  " + tab2[2, 1] + "  ||  " + tab2[2, 2]);
                Console.WriteLine("     7||    8||    9");
                Console.WriteLine(" ");
                if (!ganador && cantturnos < 9)
                {
                    if (turnojugador1)
                    {
                        ficha = "O";
                        valor = 1;
                        objetivo = 1;
                        Console.WriteLine("Turno del jugador 1 (X)");
                    }
                    else
                    {
                        ficha = "X";
                        valor = 2;
                        objetivo = 8;
                        Console.WriteLine("Turno del jugador 2 (O)");
                    }
                    Console.WriteLine("Ingrese la Posición (1-9):");
                    do
                    {
                        pos = int.Parse(Console.ReadLine());
                        if (pos < 1 || pos > 9)
                        {
                            Console.WriteLine("Posición incorrecta, ingrese nuevamente: ");
                            pos = 99;
                        }
                        else
                        {
                            i = ((pos - 1) / 3) + 1;
                            j = ((pos - 1) % 3) + 1;
                            if (tab1[i - 1, j - 1] != 0)
                            {
                                pos = 99;
                                Console.WriteLine("Posición incorrecta, ingrese nuevamente: ");
                            }
                        }
                    } while (pos == 99);
                    cantturnos = cantturnos + 1;
                    tab1[i - 1, j - 1] = valor;
                    tab2[i - 1, j - 1] = ficha;
                    aux_d1 = 1;
                    aux_d2 = 1;
                    for (i = 1; i <= 3; i++)
                    {
                        aux_i = 1;
                        aux_j = 1;
                        aux_d1 = aux_d1 * tab1[i - 1, i - 1];
                        aux_d2 = aux_d2 * tab1[i - 1, 3 - i];
                        for (j = 1; j <= 3; j++)
                        {
                            aux_i = aux_i * tab1[i - 1, j - 1];
                            aux_j = aux_j * tab1[j - 1, i - 1];
                        }
                        if (aux_i == objetivo || aux_j == objetivo)
                        {
                            ganador = true;
                        }
                    }
                    if (aux_d1 == objetivo || aux_d2 == objetivo)
                    {
                        ganador = true;
                    }
                    else
                    {
                        turnojugador1 = !turnojugador1;
                    }
                }
                else
                {
                    if (ganador)
                    {
                        Console.WriteLine("Ganador: ");
                        if (turnojugador1)
                        {
                            Console.WriteLine("Jugador 1!");
                        }
                        else
                        {
                            Console.WriteLine("Jugador 2!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Empate!");
                    }
                    terminado = true;
                }
            }
            Console.ReadKey();
        }

    }
    
}

2.2.-COMPILACIÓN :



EJERCICIO #2:

CREAR UN PROGRAMA PARA INGRESAR DOS MATRICES, VERIFICAR SI ES DESARROLLABLE LAS DOS MATRICES INGRESADAS, Y DE SERLO,  QUE DESARROLLE UNA DE LAS SIGUIENTES ACCIONES DEL UN MENÚ:
1) SUMA.
2)RESTA.
3)MULTIPLICACIÓN.
4)TRANSPUESTA.
EL PROGRAMA DEBE PEDIR SI DESEA SEGUIR DESARROLLANDO ALGUNA OTRA OPCIÓN O SALIR.

1.-PSEINT :

1.1.-CODIFICACIÓN :

Algoritmo Matrices
Definir n,f,c,c1,f1,c2,f2,opcion Como Entero;
Definir respuesta Como Caracter;
Definir M1,M2,M3 como entero;
Dimension  M1(100,100);
Dimension  M2(100,100);
Dimension  M3(100,100);
Escribir "Ingrese Matriz 1 ";
Escribir "Ingrese numero de columnas:";
leer c1;
Escribir "Ingrese numero de filas:";
leer f1;
Para f<-1 Hasta f1 Con Paso 1 Hacer
Para c<-1 Hasta c1 Con Paso 1 Hacer
Escribir "A[",f,"][",c,"]: ";
Leer M1(f,c);
FinPara;
FinPara
Escribir "Ingrese Matriz 2 ";
Escribir "Ingrese numero de columnas:";
leer c2;
Escribir "Ingrese numero de filas:";
leer f2;
Para f<-1 Hasta f2 Con Paso 1 Hacer
Para c<-1 Hasta c2 Con Paso 1 Hacer
Escribir "B[",f,"][",c,"]: ";
Leer M2(f,c);
FinPara
FinPara
si f1==f2 && c1==c2 entonces
Repetir
Escribir "MENU";
Escribir "1-Suma";
Escribir "2-Resta";
Escribir "3-Multiplicacion";
Escribir "4-Transpuesta";
Escribir "Ingresar opcion";
leer opcion;
segun opcion hacer
1:
Para f<-1 Hasta f2 Con Paso 1 Hacer
Para c<-1 Hasta c2 Con Paso 1 Hacer
M3(f,c)<-M1(f,c)+M2(f,c);
Escribir "A[",f,"][",c,"]: ",M1(f,c)," + ","B[",f,"][",c,"]: ",M2(f,c)," = ","C[",f,"][",c,"]: ",M3(f,c);
FinPara
FinPara
2:
Para f<-1 Hasta f2 Con Paso 1 Hacer
Para c<-1 Hasta c2 Con Paso 1 Hacer
M3(f,c)<-M1(f,c)-M2(f,c);
Escribir "A[",f,"][",c,"]: ",M1(f,c)," - ","B[",f,"][",c,"]: ",M2(f,c)," = ","C[",f,"][",c,"]: ",M3(f,c);
FinPara
FinPara
3:
Para f<-1 Hasta f2 Con Paso 1 Hacer
Para c<-1 Hasta c2 Con Paso 1 Hacer
M3(f,c)<-M1(f,c)*M2(f,c);
Escribir "A[",f,"][",c,"]: ",M1(f,c)," x ","B[",f,"][",c,"]: ",M2(f,c)," = ","C[",f,"][",c,"]: ",M3(f,c);
FinPara
FinPara
4:
Para f<-1 Hasta f2 Con Paso 1 Hacer
Para c<-1 Hasta c2 Con Paso 1 Hacer
M3(f,c)<-M1(f,c);
M1(f,c)<-M2(f,c);
M2(f,c)<-M3(f,c);
Escribir "A[",f,"][",c,"]: ",M2(f,c)," -> ","A[",f,"][",c,"]: ",M1(f,c);
Escribir "B[",f,"][",c,"]: ",M1(f,c)," -> ","B[",f,"][",c,"]: ",M2(f,c);
FinPara
FinPara
FinSegun
Escribir  "¿Desea seguir operando con las matrices? S/N ";
leer respuesta;
Hasta Que respuesta = 'N';
Sino
Escribir "No se puede operar estas matrices";
FinSi
FinAlgoritmo

1.2-COMPILACIÓN :





2.-VISUAL STUDIO :

2.1.-CODIFICACIÓN :


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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int c;
            double c1;
            double c2;
            int f;
            double f1;
            double f2;
            int opcion;
            string respuesta;
            int[,] m1 = new int[100, 100];
            int[,] m2 = new int[100, 100];
            int[,] m3 = new int[100, 100];
            Console.WriteLine("Ingrese Matriz 1 ");
            Console.WriteLine("Ingrese numero de columnas:");
            c1 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Ingrese numero de filas:");
            f1 = Double.Parse(Console.ReadLine());
            for (f = 1; f <= f1; f++)
            {
                for (c = 1; c <= c1; c++)
                {
                    Console.WriteLine("A[" + f + "][" + c + "]: ");
                    m1[f - 1, c - 1] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine("Ingrese Matriz 2 ");
            Console.WriteLine("Ingrese numero de columnas:");
            c2 = Double.Parse(Console.ReadLine());
            Console.WriteLine("Ingrese numero de filas:");
            f2 = Double.Parse(Console.ReadLine());
            for (f = 1; f <= f2; f++)
            {
                for (c = 1; c <= c2; c++)
                {
                    Console.WriteLine("B[" + f + "][" + c + "]: ");
                    m2[f - 1, c - 1] = int.Parse(Console.ReadLine());
                }
            }
            if (f1 == f2 && c1 == c2)
            {
                do
                {
                    Console.WriteLine("MENU");
                    Console.WriteLine("1-Suma");
                    Console.WriteLine("2-Resta");
                    Console.WriteLine("3-Multiplicacion");
                    Console.WriteLine("4-Transpuesta");
                    Console.WriteLine("Ingresar opcion");
                    opcion = int.Parse(Console.ReadLine());
                    switch (opcion)
                    {
                        case 1:
                            for (f = 1; f <= f2; f++)
                            {
                                for (c = 1; c <= c2; c++)
                                {
                                    m3[f - 1, c - 1] = m1[f - 1, c - 1] + m2[f - 1, c - 1];
                                    Console.WriteLine("A[" + f + "][" + c + "]: " + m1[f - 1, c - 1] + " + " + "B[" + f + "][" + c + "]:" + m2[f - 1, c - 1] + " = " + "C[" + f + "][" + c + "]: " + m3[f - 1, c - 1]);
                                }
                            }
                            break;
                        case 2:
                            for (f = 1; f <= f2; f++)
                            {
                                for (c = 1; c <= c2; c++)
                                {
                                    m3[f - 1, c - 1] = m1[f - 1, c - 1] - m2[f - 1, c - 1];
                                    Console.WriteLine("A[" + f + "][" + c + "]: " + m1[f - 1, c - 1] + " - " + "B[" + f + "][" + c + "]:" + m2[f - 1, c - 1] + " = " + "C[" + f + "][" + c + "]: " + m3[f - 1, c - 1]);
                                }
                            }
                            break;
                        case 3:
                            for (f = 1; f <= f2; f++)
                            {
                                for (c = 1; c <= c2; c++)
                                {
                                    m3[f - 1, c - 1] = m1[f - 1, c - 1] * m2[f - 1, c - 1];
                                    Console.WriteLine("A[" + f + "][" + c + "]: " + m1[f - 1, c - 1] + " x " + "B[" + f + "][" + c + "]:" + m2[f - 1, c - 1] + " = " + "C[" + f + "][" + c + "]: " + m3[f - 1, c - 1]);
                                }
                            }
                            break;
                        case 4:
                            for (f = 1; f <= f2; f++)
                            {
                                for (c = 1; c <= c2; c++)
                                {
                                    m3[f - 1, c - 1] = m1[f - 1, c - 1];
                                    m1[f - 1, c - 1] = m2[f - 1, c - 1];
                                    m2[f - 1, c - 1] = m3[f - 1, c - 1];
                                    Console.WriteLine("A[" + f + "][" + c + "]: " + m2[f - 1, c - 1] +"  -> " + "A[" + f + "][" + c + "]: " + m1[f - 1, c - 1]);
                                    Console.WriteLine("B[" + f + "][" + c + "]: " + m1[f - 1, c - 1] + " -> " + "B[" + f + "][" + c + "]: " + m2[f - 1, c - 1]);
                                }
                            }
                            break;
                    }
                    Console.WriteLine("¿Desea seguir operando con las matrices? S/N ");
                    respuesta = Console.ReadLine();
                } while (!respuesta.Equals("N"));
            }
            else
            {
                Console.WriteLine("No se puede operar estas matrices");
            }
        }
    }
}

2.2.-COMPILACIÓN :