2011. 6. 1. 12:18

C# 구구단 출력 프로그램

  1: using System;
  2: using System.Collections.Generic;
  3: using System.Linq;
  4: using System.Text;
  5: 
  6: namespace GuguDan
  7: {
  8:     class Program
  9:     {
 10:         static void Main(string[] args)
 11:         {
 12:             int dan, result;
 13: 
 14:             Console.Write("출력할 단을 입력 (0은 전체 출력) : ");
 15:             dan = int.Parse(Console.ReadLine());
 16: 
 17:             if (dan == 0)
 18:             {
 19:                 for (int i = 1; i <= 9; i++)
 20:                 {
 21:                     for (int j = 1; j <= 9; j++)
 22:                     {
 23:                         result = j * i;
 24:                         Console.Write("{0}*{1}={2}\t", j, i ,result);
 25:                     }
 26:                     Console.WriteLine();               
 27:                 }             
 28:             }
 29: 
 30:             else
 31:             {
 32:                 for (int i = 0; i <= 9; i++)
 33:                 {
 34:                     result = dan * i;
 35:                     Console.WriteLine("{0} * {1} = {2}", dan, i, result);
 36:                 }
 37:             }
 38:         }
 39:     }
 40: }