본문으로 바로가기

출제 링크 : https://www.acmicpc.net/problem/8393

 

8393번: 합

n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.

www.acmicpc.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Solution
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int sum = 0;

            if(1 <= n && n <=10000)
            {
                for(int i=1; i<=n; i++)
                {
                    sum += i;
                }
                Console.WriteLine(sum);
            }
        }     
    }
}