//3개의 정수를 콘솔로부터 입력 받아 내림차순으로 정렬하여 출력하는 프로그램

using System;
using System.Collections;
using System.Text;

namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   int[] bubblesort = new int[3];//입력 후 최종 sort결과
   int temp = 0;

   Console.WriteLine("출력-----------------------------");
   Console.WriteLine();

   //숫자 입력 부분
   for (int i = 0; i < 3; i++)
   {
    Console.WriteLine("{0}번째", i + 1);
    bubblesort[i] = Int32.Parse(Console.ReadLine());
   }
   

   //숫자 정렬 부분
   for (int i = 0; i < 2; i++)
   {
    for (int j = 0; j < 2 - i; j++)
    {
     //두 숫자 비교해서 뒷쪽이 크면 교환(정렬은 bubble sort 알고리즘)
     if (bubblesort[j] > bubblesort[j + 1])
     {
      temp = bubblesort[j];
      bubblesort[j] = bubblesort[j + 1];
      bubblesort[j + 1] = temp;
     }
    }//end of for2
   }//end of for1

   Console.WriteLine();

   //정렬된 숫자 출력 부분
   for (int i = 0; i < 3; i++)
   {
    Console.WriteLine(bubblesort[i]);
   }//end of for

   Console.WriteLine("---------------------------------");
   Console.ReadLine();
  }//end of Main
 }//end of Program_Class
}//end of namespeace


+ Recent posts