Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Unidad03
- {
- class Program
- {
- //static int[] memo;
- static void Main(string[] args)
- {
- Ejercicio9();
- Console.ReadKey();
- }
- static void Ejercicio1()
- {
- int nro1, nro2;
- Console.WriteLine("Ingrese el primer número: ");
- nro1 = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Ingrese el segundo número: ");
- nro2 = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("El resultado de la suma de "+nro1+" y "+nro2+" es "+(nro1+nro2));
- }
- static void Ejercicio2()
- {
- int anio;
- Console.WriteLine("Ingrese el año: ");
- anio = Convert.ToInt32(Console.ReadLine());
- if((anio % 4 == 0 && anio % 100 != 0) || (anio % 100 == 0 && anio % 400 == 0))
- {
- Console.WriteLine("Es bisiesto");
- } else {
- Console.WriteLine("No es bisiesto");
- }
- }
- static void Ejercicio3()
- {
- Console.WriteLine("Diez: "+fib(10));
- }
- static int fib(int n)
- {
- /*
- * Revisar tema de memo{}
- */
- int f;
- if (n <= 2)
- f = 1;
- else
- f = fib(n - 1) + fib(n - 2);
- return f;
- }
- static void Ejercicio4()
- {
- int i;
- for (i = 1; i <= 100; i++)
- {
- if (i % 2 == 0)
- {
- Console.WriteLine(i);
- }
- }
- }
- /*
- * ¿Existe algo como mes['enero'] = 1; ?
- */
- static void Ejercicio5()
- {
- String mes;
- Boolean encontrado;
- encontrado = false;
- String[] meses = new String[13];
- meses[1] = "Enero";
- meses[2] = "Febrero";
- meses[3] = "Marzo";
- meses[4] = "Abril";
- meses[5] = "Mayo";
- meses[6] = "Junio";
- meses[7] = "Julio";
- meses[8] = "Agosto";
- meses[9] = "Septiembre";
- meses[10] = "Octubre";
- meses[11] = "Noviembre";
- meses[12] = "Diciembre";
- Console.WriteLine("Ingrese el número del mes: ");
- mes = Console.ReadLine();
- for(int i=1;i<=12;i++)
- {
- if(mes.ToLower() == meses[i].ToLower())
- {
- Console.WriteLine(meses[i]+" "+i);
- encontrado = true;
- }
- }
- if (!encontrado)
- {
- Console.WriteLine("El mes no existe");
- }
- }
- static void Ejercicio6()
- {
- int nro;
- Console.WriteLine("Ingrese el número que desea convertir a romano: ");
- nro = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine(ConvertirRomano(nro));
- }
- static string ConvertirRomano(int nro)
- {
- if ((nro < 0) || (nro > 3999)) throw new ArgumentOutOfRangeException("Debe insertar un valor entre 1 y 3999");
- if (nro < 1) return string.Empty;
- if (nro >= 1000) return "M" + ConvertirRomano(nro - 1000);
- if (nro >= 900) return "CM" + ConvertirRomano(nro - 900);
- if (nro >= 500) return "D" + ConvertirRomano(nro - 500);
- if (nro >= 400) return "CD" + ConvertirRomano(nro - 400);
- if (nro >= 100) return "C" + ConvertirRomano(nro - 100);
- if (nro >= 90) return "XC" + ConvertirRomano(nro - 90);
- if (nro >= 50) return "L" + ConvertirRomano(nro - 50);
- if (nro >= 40) return "XL" + ConvertirRomano(nro - 40);
- if (nro >= 10) return "X" + ConvertirRomano(nro - 10);
- if (nro >= 9) return "IX" + ConvertirRomano(nro - 9);
- if (nro >= 5) return "V" + ConvertirRomano(nro - 5);
- if (nro >= 4) return "IV" + ConvertirRomano(nro - 4);
- if (nro >= 1) return "I" + ConvertirRomano(nro - 1);
- throw new ArgumentOutOfRangeException("error");
- }
- static void Ejercicio7()
- {
- int n;
- Console.WriteLine("Ingrese el máximo del intervalo: ");
- n = Convert.ToInt32(Console.ReadLine())+1;
- int[] primos = new int[n];
- // Obtener todos los números primos desde 0 a n
- for (int i = 1; i <= (n-1); i++)
- {
- if (EsPrimo(i))
- primos[i] = 1;
- else
- primos[i] = 0;
- }
- // Comparamos los números encontrados
- for (int k = 1; k <= (n-3); k++)
- {
- if (primos[k] == 1 && primos[k + 2] == 1)
- Console.WriteLine("(" + k + "," + (k + 2) + ")");
- }
- }
- static Boolean EsPrimo(int n)
- {
- int a=0,i;
- for(i = 1; i < (n + 1); i++)
- {
- if(n%i == 0)
- a++;
- }
- if(a != 2)
- return false;
- else
- return true;
- }
- static void Ejercicio8()
- {
- int intentos = 0;
- String pass = "abc";
- String ingreso;
- while(intentos < 4)
- {
- Console.WriteLine("Ingrese la contraseña ");
- ingreso = Console.ReadLine();
- if(ingreso != pass)
- {
- Console.WriteLine("Contraseña Incorrecta.");
- intentos++;
- } else {
- Console.WriteLine("Contraseña Correcta.");
- break;
- }
- }
- }
- static void Ejercicio9()
- {
- int filas,cant_fila;
- cant_fila = 1;
- Console.WriteLine("Ingrese la cantidad de filas: ");
- filas = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < filas; i++)
- {
- for (int j = 0; j < filas - i; j++)
- {
- Console.Write(" "); Console.Write(" ");
- }
- for (int k = 0; k < cant_fila; k++)
- {
- Console.Write("* ");
- }
- Console.Write("\n");
- cant_fila += 2;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment