//  1부터 100까지 짝수의 합을 구하는 프로그램을 작성하시오.
using System;

public class 짝수의합
{
    public static void Main(string[] args)
    {
        //[1] Input
        int sum = 0;
        //[2] Process
        for (int i = 1; i <= 100; i++)
  {
            if (i % 2 == 0)
         {
          sum += i;
         }
   
  }

        //[3] output
        Console.WriteLine("1~100까지 짝수의 합 : {0}"
            , String.Format("{0:###,###}", sum)); // 2,550
    }

}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

13. 비트연산자  (0) 2009.08.04
12. 시프트연산자  (0) 2009.08.04
10. 상수  (0) 2009.08.04
9. 변수  (0) 2009.08.04
8. 이스케이프시퀀스  (0) 2009.08.04
Posted by holland14
: