Advertisement
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;
- using System.Threading.Tasks;
- namespace TP2Punto6
- {
- class Program
- {
- static void cambioBase(int num)
- {
- Stack<int> valor = new Stack<int>();
- int Base = 2, aux = num;
- while (aux>0)
- {
- valor.Push(aux % Base);
- aux = aux / Base;
- }
- Console.WriteLine("\nEn Base 10: {0}", num);
- Console.Write("\nEn Base 2: ");
- while (valor.Count>0)
- {
- Console.Write(valor.Pop());
- }
- }
- static bool validarEntero(string cadena)
- {
- bool val = false;
- try
- {
- int aux = int.Parse(cadena);
- return !val;
- }
- catch (FormatException f)
- {
- Console.WriteLine("\n\nERROR: El dato ingresado es incorrecto..");
- }
- return val;
- }
- static void Main(string[] args)
- {
- string cadena;
- int resp=0;
- do
- {
- Console.Clear();
- Console.Write("Ingrese Número en Base 10: ");
- cadena = Console.ReadLine();
- if (validarEntero(cadena))
- {
- int num = int.Parse(cadena);
- cambioBase(num);
- }
- Console.WriteLine("\n\n1- Volver a ingresar número.");
- Console.WriteLine("2- Salir.");
- cadena = Console.ReadLine();
- if (validarEntero(cadena))
- {
- resp = int.Parse(cadena);
- }
- } while (resp!=2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement