Practica 5

4

Click here to load reader

description

practica c#

Transcript of Practica 5

Page 1: Practica 5

PRACTICA 5

ESTRUCTURA DE REPETICIÓN

COMPETENCIA: Realizar programas que

implementen estructuras de repetición

ACTIVIDADES:

a) DEC – OCT

b) DEC - HEX

PAREDES VILLEGAS ROGELIO

11090173

CATEDRATICO:

BARCENAS MARTINEZ VENANCIO

GRUPO: XA

DESARROLLO DE APLIC SOBRE PLAT.

WINDOWS

Page 2: Practica 5

a) DECIMAL A OCTAL

static void Main(string[] args)

{

int numero;

String octal = "";

Console.Write("Escribe el número decimal ");

numero = int.Parse(Console.ReadLine());

while (numero > 0)

{

octal = numero % 8 + octal;

numero /= 8;

}

Console.WriteLine("El numero Octal es: " + octal);

Console.ReadKey();

}

Page 3: Practica 5

b) DECIMAL A HEXADECIMAL

static void Main(string[] args)

{

int numero;

int residuo = 0;

String hexa = "";

Console.Write("Escribe el número decimal ");

numero = int.Parse(Console.ReadLine());

while (numero > 0)

{

residuo = numero % 16;

numero /= 16;

if (residuo == 10)

hexa += "A";

else if (residuo == 11)

hexa += "B";

else if (residuo == 12)

hexa += "C";

else if (residuo == 13)

hexa += "D";

else if (residuo == 14)

hexa += "E";

else if (residuo == 15)

hexa += "F";

else

hexa += residuo;

}

Console.WriteLine("El numero hexadecimal es: " + Invertir(hexa));

Console.ReadKey();

Page 4: Practica 5

}

public static string Invertir(string s)

{

char[] arr = s.ToCharArray();

Array.Reverse(arr);

return new string(arr);

}