Pages

miércoles, 23 de enero de 2013

Determinar las dos peores notas de cinco Codigo Fuente en C#

Problema
Hacer un programa o algoritmo que si  se ingresan 5 notas de un alumno, publicar las 2 peores notas

Solución
  • Entrada: 15, 10, 13, 8,19 
  • Salida: 10, 8
Codigo Fuente en C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int u=0,tem;
     int []Nota=new int[5];
     for(int i=0;i<5;i++){
          Console.WriteLine("Ingresa Nota");
          Nota[i] = Convert.ToInt16(Console.ReadLine());
     }
     while(u!=4){
         u=0;
         for(int k=0;k<4;k++){
             if(Nota[k]<=Nota[k+1]){
                 u++;
             }else{
                tem=Nota[k];
                Nota[k]=Nota[k+1];
  Nota[k+1]=tem;
             }
         }
     }
     Console.WriteLine("Las 2 peores notas obtenidas son: " +
            (Nota[0]) + " y " + (Nota[1]));
      Console.ReadLine();
        }
    }
}

0 comentarios:

Publicar un comentario