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.

martes, 24 de noviembre de 2015

Ampliación tema 4 (3)

0





21.- perfecto



22.-

parte del 23.- funciona con 2 números.
using System;

namespace a4._22
{
    class Program
    {
        //Descomponemos en factores primos.
        static int factor(int x)
        {
            int factor;
            //buscamos numeros primos
            for (int i = 2; i <= x; i++)
            {
                int contador = 0;
                for (int j = 2; j < i; j++)
                {
                    if (i % j == 0)
                    {
                        contador++;
                    }
                }
                //si el número es primo
                if (contador == 0)
                {
                    //y divisible por el numero 
                    if (x % i == 0)
                    {
                        //obtenemos el factor primo
                        return factor = i;
                    }
                }
            }
            return 1;
        }
        static int multiplo(int x, int y)
        {
            int total = 1, igual = 1, distinto1 = 1, distinto2 = 1;
            if (x == y)
            {
                igual = x;
                return total = total * x;
            }
            else if (x != y)
            {
                distinto1 = x;
                distinto2 = y;
                return total = total * x * y;
            }
            if (igual == distinto1)
            {
                return total = total / distinto1;
            }
            else if (igual == distinto2)
            {
                return total = total / distinto2;
            }
            return 1;
        }
        static int divisor(int x, int y)
        {
            int total = 1, igual = 1, distinto1 = 1, distinto2 = 1;
            if (x == y)
            {
                igual = x;
                return igual;
            }
            else if (x != y)
            {
                distinto1 = x;
                distinto2 = y;
            }
            if (igual == distinto1)
            {
                return total =distinto1;
            }
            else if (igual == distinto2)
            {
                return total = distinto2;
            }
            return 1;
        }
        static void Main(string[] args)
        {
            int x, y, total = 1, fx, fy, aux = 0, menu;
            while (aux == 0)
            {
                Console.WriteLine("Menú:");
                Console.WriteLine("1. mcm");
                Console.WriteLine("2. mcd");
                Console.WriteLine("3. salir");
                menu = int.Parse(Console.ReadLine());
                if (menu == 1)
                {
                    Console.WriteLine("Número 1:");
                    x = int.Parse(Console.ReadLine());
                    Console.WriteLine("Número 2:");
                    y = int.Parse(Console.ReadLine());
                    while (x != 1 && y != 1)
                    {
                        fx = factor(x);
                        fy = factor(y);
                        total = total * multiplo(fx, fy);
                        x = x / fx;
                        y = y / fy;
                    }
                    Console.WriteLine("el mcm es:");
                    Console.WriteLine(total);
                }
                else if (menu == 2)
                {
                    Console.WriteLine("Número 1:");
                    x = int.Parse(Console.ReadLine());
                    Console.WriteLine("Número 2:");
                    y = int.Parse(Console.ReadLine());
                    while (x != 1 && y != 1)
                    {
                        fx = factor(x);
                        fy = factor(y);
                        total = total * divisor(fx, fy);
                        x = x / fx;
                        y = y / fy;
                    }
                    Console.WriteLine("el mcd es:");
                    Console.WriteLine(total);
                }
                else if (menu == 3)
                {
                    Console.WriteLine("bye, bye...");
                    aux = 1;
                }
                else
                {
                    Console.WriteLine("Opción incorrecta");
                }
                Console.ReadKey();
                Console.Clear();
            }
        }
    }
}



Related Posts:

  • Estación de mensajes Elige una interfaz entre todas las desarrolladas y añade una sencilla etiqueta denominada lEstacion. Cada vez que un elemento reciba el foco del p… Read More
  • Añade ayuda en la interfaz Añade un control de tipo ToolTip Déjalo siempre visible usando la propiedad ShowAlways. De forma manual en cada elemento que quieras que tenga asoc… Read More
  • Repasando AD --> SystemEjemplo 1 Cuenta caracteres import java.io.*; class CuentaCaracteres { /*throw IOException es un control de errores obligado por el lenguaje Ja… Read More
  • Control de errores en visual basic Visual Basic admite el control estructurado de excepciones (errores), que permite al programa detectar y recuperarse posiblemente de los errores dura… Read More
  • Repasando AD -> StreamsUn stream representa un flujo de información, una secuencia ordenada de datos procedente de una fuente o dirigida a un destino. Un stream es una secue… Read More

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)