본문 바로가기
언어/[C#]

[C#] 연산자 +, -, *, /, ++, +=, -- -=, *=, /=

by 조랩 2023. 2. 25.
using System;

namespace MyFirstProgram
{
    internal class Program
    {

        static void Main(string[] args) // main method
        {

            int friends = 5;
            friends = friends + 1; // 6
            friends++; // 1씩 증가해줌 -> 7
            friends += 2; // 뒤에 적은 숫자만큼 증가해줌 -> 9
            Console.WriteLine(friends);
            
            int friends = 5;
            friends = friends - 1; // 4
            friends--; // 1씩 감소해줌 -> 3
            friends -= 2; // 뒤에 적은 숫자만큼 감소해줌 -> 1
            Console.WriteLine(friends);
            
            int friends = 5;
            friends = friends * 2; // 10
            friends *= 2; // 뒤에 적은 숫자만큼 곱해줌 -> 20
            Console.WriteLine(friends);
            
            int friends = 12;
            friends = friends / 2; // 6
            friends /= 2; // 뒤에 적은 숫자만큼 나눠줌 -> 3
            Console.WriteLine(friends);

        }
    }
}
728x90