Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

17. 산술연산자 본문

초보자를 위한 C# 200제/C# 입문

17. 산술연산자

빌드이너프 2024. 9. 12. 20:38

산술연산자는 4개의 사칙연산자(+, -, *, /)와 나머지(%) 연산자로 총 5가지가 있다(연산의 결과는 숫자)

산술연산에서 중요한 것은 자료형(피연산자의 자료형에 따라 계산 결과값의 자료형이 결정됨)

 

코드

using System;


namespace A017_ArithmeticOperators
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("정수의 계산");
            Console.WriteLine(123 + 45);
            Console.WriteLine(123 - 45);
            Console.WriteLine(123 * 45);
            Console.WriteLine(123 / 45);
            Console.WriteLine(123 % 45);

            Console.WriteLine("실수의 계산");
            Console.WriteLine(123.45 + 67.89);
            Console.WriteLine(123.45 - 67.89);
            Console.WriteLine(123.45 * 67.89);
            Console.WriteLine(123.45 / 67.89);
            Console.WriteLine(123.45 % 67.89);

        }
    }
}

 

결과