Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unidad 5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

namespace ConsoleApp22

internal class Program

static void Main(string[] args)

double a, b, resultado = 0;

int opcion;

do //Inicia ciclo do - while;

Console.WriteLine("1.- suma.......");

Console.WriteLine("2.- resta.......");

Console.WriteLine("3.-division.......");

Console.WriteLine("4.-multiplicar......");

Console.WriteLine("5.-salir........");

Console.WriteLine("Introduzca la opcion deseada: ");

opcion = Convert.ToInt16(Console.ReadLine());

Console.WriteLine("Introduzca el valor de a: ");

a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Introduzca el valor de b: ");

b = Convert.ToDouble(Console.ReadLine());

switch (opcion)

case 1:

resultado = a + b;

break;

case 2:

resultado = b - a;

break;

case 3:

if (b != 0)

resultado = a / b;

else

Console.WriteLine("Divisor invalido....");

break;

case 4:

resultado = a * b;

break;

case 5:

Console.WriteLine("saliendo.....");

Thread.Sleep(5000);

break;

default:

Console.WriteLine("Opcion invalida.....");

break;

}
Console.WriteLine("El resultado es : " + resultado);

Console.ReadKey();

Console.Clear();

} while (opcion != 5);

}
namespace ConsoleApp23

internal class Program

static void Main(string[] args)

{ //inicio

int[] arreglo1 = new int[10]; //Declaracion de un arreglo unidimensional o vector

for (int i = 0; i < arreglo1.Length; i++) //Ciclo para insertar elementos en el arreglo

Console.Write("arreglo[{0}]=",i);

arreglo1[i] = Convert.ToInt16(Console.ReadLine());

Console.ReadKey();

//fin

}
internal class Program
{
static void Main(string[] args)
{
string texto;
Console.Write("ontroduzca el texto: ");
texto= Console.ReadLine();
//Declaracion de arreglo tipo char longitud del texto
char[] caracter = texto.ToCharArray();

foreach (var item in caracter)


{
Console.WriteLine(item);

}
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp28
{
internal class Program
{
static void Main(string[] args)
{
string ps = "cuauhtemoc".ToUpper();
int oport = 0;
char car;
bool ban=false;
bool[] pb = new bool[ps.Length];
for (int i = 0; i<ps.Length; i++)
{
pb[i] = false;
}
do
{
Console.WriteLine("\n Adivina mi palabra");
for (int i = 0; i < ps.Length; i++)
{
if (pb[i] == false)
Console.Write("_");
else
Console.Write(" " + ps[i] + " ");
}
Console.WriteLine("\n Dame una letra");
car = char.Parse(Console.ReadLine().ToUpper());
for (int i = 0; i < ps.Length; i++)
{
if (car == ps[i])
{
pb[i] = true;
ban = true;
}
}
if (ban == false)
{
oport = oport + 1;
Console.WriteLine("Has perdido tu {0} oportunidad");
Console.ReadKey();
if (oport == 3)
{
Console.WriteLine("Te has Horcado");
Console.ReadKey();
break;
}

}
Console.Clear();
} while (ganar(pb) != true);
if (oport != 3)
Console.WriteLine("ganaste");
Console.ReadKey();
}
static bool ganar(bool[] b)
{
bool a = true;
for (int i = 0; i < b.Length;i++)
{
if (b[i] == false)
a = false;
}
return a;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp30
{
internal class Program
{
static void Main(string[] args)
{
double[,] A, B, C;
int fila, columna;
Console.WriteLine("Dimension de la matriz . .");
Console.Write("Intriduzca el numero de fila: ");
fila = Convert.ToInt16(Console.ReadLine());
Console.Write("Introduzca el numero de columnas: ");
columna = Convert.ToInt16(Console.ReadLine());
A = new double[fila, columna];
B = new double[fila, columna];
C = new double[fila, columna];
for (int i = 0; i < fila; i++) //Introducir los valores de la matriz A
{
for (int j = 0; j < columna; j++)
{
Console.Write("A[{0},{1}]", i, j);
A[i, j] = Convert.ToDouble(Console.ReadLine());
}
Console.ReadKey();
Console.Clear();
}
for (int i = 0; i < fila; i++) //Introducir los valores de la matriz B
{
for (int j = 0; j < columna; j++)
{
Console.Write("B[{0},{1}]", i, j);
B[i, j] = Convert.ToDouble(Console.ReadLine());
}
Console.ReadKey();
Console.Clear();
}
for (int i = 0; i < fila; i++) //Calcular la suma de matrices: A+B = C
{
for (int j = 0; j < columna; j++)
{
C[i, j] = A[i, j] + B[i, j];
Console.Write("C[{0},{1}]={2}", i, j, C[i, j]);

}
Console.ReadKey();
Console.Clear();
}
} } }
internal class Program
{
static void Main(string[] args)
{
int[,] matriz;
int fila, columna;
Console.Write("Introduzca el numero de filas:");
fila = Convert.ToInt16(Console.ReadLine());
Console.Write("Introduzca el numero de columnas:");
columna= Convert.ToInt16(Console.ReadLine());
matriz = new int[fila, columna];
for (int i = 0; i < fila; i++)
{
for (int j = 0; j < columna; j++)
{
if (matriz[i, j] % 2 ==0)
Console.WriteLine("Matriz[{0},{1}] = {2} es NUMERO PAR", i, j, matriz[i, j]);
else
Console.WriteLine("Matriz[{0},{1}] = {2} es NUMERO IMPAR", i, j, matriz[i,j]);
}
}
Console.ReadKey();
}
}
}

You might also like