lunes, 2 de mayo de 2016

DESARROLLO DE EXAMEN

DESARROLLO DE EXAMEN

1. PROGRAMA PARA CALCULAR EL NUMERO DE DÍGITOS DE UN NUMERO ENTERO Y POSITIVO


        {
            int n = 0, nd = 0;
            Console.Writeline("Ingrese numero");
            n=Convert.ToInt32(Console.ReadLine());

            while (n>0)
            {
                n = n / 10;
                nd++;
            }
            
            Console.WriteLine("el numero de digitos {0} ", nd);
            Console.ReadKey();
        }

2. PROGRAMA PARA CALCULAR EL MAYOR Y EL MENOR DE 4 NÚMEROS

int a, b, c, d, may, men;

            Console.WriteLine("Ingrese primer numero");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("Ingrese segundo numero");
            b = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("Ingrese tercer numero");
            c = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("Ingrese cuarto numero");
            d = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            if (a > b) { 
                if (a > c)  
                    if (a > d)
                    { may = a;
                        Console.WriteLine("El numero mayor es {0} ", may);
                    }
                    else if (c > d)
                    { may = c;
                        Console.WriteLine("El numero mayor es {0} ", may);
                    }
                    else { may = d;
                        Console.WriteLine("El numero mayor es {0} ", may);
                    }
            }
            else
                    if (b > c)
                        if (b > d) { 
                                may = b;
                                Console.WriteLine("El numero mayor es {0} ", may);
                            }
                        else { may = d;
                             Console.WriteLine("El numero mayor es {0} ", may);
                             }
                    else
                        if (c > d) { 
                             may = c;
                            Console.WriteLine("El numero mayor es {0} ", may);
                            }
                        else { may = d;
                         Console.WriteLine("El numero mayor es {0} ", may);
                }

            // para el menor
            if (a < b)
            {
                if (a < c)
                    if (a < d)
                    {
                        men = a;
                        Console.WriteLine("El numero menor es {0} ", men);
                    }
                    else if (c < d)
                    {
                        men = c;
                        Console.WriteLine("El numero menor es {0} ", men);
                    }
                    else
                    {
                        men = d;
                        Console.WriteLine("El numero menor es {0} ", men);
                    }
            }
            else
                    if (b < c)
                if (b < d)
                {
                    men = b;
                    Console.WriteLine("El numero menor es {0} ", men);
                }
                else
                {
                    men = d;
                    Console.WriteLine("El numero menor es {0} ", men);
                }
            else
                        if (c < d)
            {
                men = c;
                Console.WriteLine("El numero menor es {0} ", men);
            }
            else
            {
                men = d;
                Console.WriteLine("El numero menor es {0} ", men);
            }

            Console.ReadKey();
        }

No hay comentarios.:

Publicar un comentario