Bienvenidos a un nuevo curso. Ahora estoy en el ciclo de grado superior: Desarrollo de aplicaciones multiplataforma. Y voy a ser parte del experimento de la formación dual. Estaré haciendo practicas durante un año, y a la vez finalizando la formación.

Deseadme suerte.

viernes, 4 de diciembre de 2015

Examen de programación

0

Corrección del examen

1.- Pasa de binario a decimal con una función recursiva.

modo profesor
using System;

namespace Examen
{
class MainClass
{
static double Adecimal(string n){

if ( (n.Length>0) && ((n[0])=='1') )
return Math.Pow(2,n.Length-1)+ Adecimal(n.Remove(0,1));
else if (n.Length !=0)
                                return Adecimal (n.Remove(0,1));
                        else
return 0;
}

public static void Main (string[] args)
{
Console.Write ("Introduce un valor en binario: ");
string n = Console.ReadLine ();
Console.Write ("El valor de {0} en decimal es: {1}",n,Adecimal(n));
            Console.ReadKey();
}
}
}

2.-  Realiza una función que calcule si un número es palíndromo. La función debe de ser recursiva.


Modo profesor
using System;

namespace Examen02
{
class MainClass
{
static bool Palindroma(string c){

if (c.Length < 2)
return true;
else 
if (c [0] == c [c.Length - 1]) {
c=c.Remove (c.Length - 1, 1);//primero borra por el final para no afectar al tamaño
c=c.Remove (0,1);
return Palindroma (c);
}
else return false;

}

public static void Main (string[] args)
{
Console.Write ("Introduce un valor para ver si es palíndromo: ");
string c = Console.ReadLine ();
Console.Write ("¿es palíndroma?: {0}",Palindroma(c));
            Console.ReadKey();
}
}
}

3.- rea el siguiente programa:



Modo profesor
using System;

namespace Examen03
{
class MainClass
{
public static void Main (string[] args)
{
                        string hueco = " ";
Console.Write ("Introduce el nivel de la pirámide: ");
int nivel = int.Parse (Console.ReadLine());
for (int i = 1; i <= nivel; i++) {
for (int j=i; j<nivel; j++)//para los huecos
Console.Write (hueco);
for (int k = 1; k <= i; k++)//para los números ascendente/
if (k==1)
Console.Write (i);
else Console.Write (k);
for (int l = i-1; l >= 1; l--)//para los números descendente/
if (l==1)
Console.Write (i);
else Console.Write (l);

}
                 Console.ReadKey();
}
}
}

4- Programa que calcula el mínimo común múltiple

Modo profesor
using System;

namespace Examen04
{
class MainClass
{
public static void Main (string[] args)
{
Console.Write("Ingrese el primer numero: ");
int num1 = int.Parse(Console.ReadLine());
Console.Write("Ingrese el segundo numero: ");
int num2 = int.Parse(Console.ReadLine());
// Seleccionamos el mayor entre num1 y num2
int mayor = Math.Max(num1, num2);
// Inicializamos la variable que almacenará el resultado
int mcm = 0;

for (int i=mayor; i<=num1*num2; i++) {

if (i%num1==0 && i%num2==0) {
mcm = i;
break;

}
}
// Mostramos el resultado en pantalla
Console.WriteLine("El m.c.m. entre "+num1+" y "+num2+" es: "+mcm);
Console.ReadKey();
}
}
}

5- Crea la siguiente pirámide pascal:


Modo profesor
using System;

namespace Examen05
{
class MainClass
{

static void PiramidePascal(int c, int[,] matriz){
string hueco = " ";

for (int i = 0; i < c; i++) {
for (int j = i; j < c; j++)//para los huecos
Console.Write (hueco);

for (int j = 0; j <= i; j++)
//imprimos los valores de la matriz
Console.Write (matriz [i, j] + " ");

Console.WriteLine ();
}
}
public static void Main (string[] args)
{
Console.Write ("Introduce la cantidad de niveles: ");
int c = int.Parse (Console.ReadLine());

int [,]matriz=new int[c,c];

for (int i=0; i<c; i++)//la columna 0 de 1's
matriz [i, 0] = 1;
for (int i = 1; i < c; i++)//la diagonal de 1¡s
matriz [i, i] = 1;

for (int i=2; i<c;i++)
for (int j=1; j<i;j++)
matriz[i,j]=matriz[i-1,j]+matriz[i-1,j-1];

PiramidePascal (c,matriz);


Console.ReadKey();

}
}
}


0 comentarios:

Publicar un comentario

Etiquetas actuales

BD (67) DEF (64) PROG (64) SQL (44) Java (29) PRACTICAS (20) php (18) DI (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) HTML (13) SGE (12) ERP (9) CONSULTAS (8) css (8) Linux (5) XML (5) Android (4) PDM (4) C (3) NetBeans (3) PSP (3) SMARTY (3) comandos (3) HOOK (2) POST (2) XSD (2) cURL (2) JS (1) MEDIA-QUERYS (1) PDO (1) RESPONSIVE (1) TPL (1) TRADUCCIÓN (1) app_inventor (1)

Todas las etiquetas

EJER (78) BD (67) DEF (64) PROG (64) SQL (44) c# (40) Programación (39) Ficheros (36) Java (29) bases de datos (21) PRACTICAS (20) lenguajes de marcas (19) AD (18) Entorno de desarrollo (18) php (18) PROCEDIMIENTOS (17) DI (16) FORM (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) lenguaje C (16) E/R (14) HTML (13) SGE (12) Sistemas informáticos (10) ERP (9) CONSULTAS (8) TRANSACCIONES (8) TRIGGER (8) VISUAL BASIC (8) css (8) FUNCIONES (7) html5 (6) Ada (5) EXAMEN (5) Linux (5) XML (5) estructuras (5) Android (4) DISEÑO (4) INTERFAZ (4) LOG (4) OpenBravo (4) PDM (4) ACTUALIZAR (3) C (3) DIAGRAMA (3) Directorios (3) NEW (3) NOR (3) NetBeans (3) OLD (3) PSP (3) SMARTY (3) comandos (3) css3 (3) AISLAMIENTOS (2) C++ (2) CONTROLERRORES (2) ELIMINAR (2) HOOK (2) INSERTAR (2) INST (2) MULTITABLA (2) POST (2) RECURSIVIDAD (2) SUBCONSULTAS (2) VISTAS (2) XSD (2) cURL (2) punteros (2) AJENA (1) BLOQUEOS (1) Byte (1) CREACION (1) CRM (1) Configuración (1) Controles (1) Datos (1) GOTFOCUS (1) IMAGENES (1) INDICES (1) JS (1) Lenght (1) MEDIA-QUERYS (1) Mingw (1) MonoDeveloped (1) OPTIMISTA (1) PDO (1) PESIMISTA (1) RESPONSIVE (1) SPEAK (1) Scanner (1) Serializacion (1) Streams (1) System (1) TPL (1) TRADUCCIÓN (1) USUARIOS (1) UseSystemPasswordChar (1) app_inventor (1) char (1) examenes (1) libreoffice (1) make (1) redes (1)