본문 바로가기
프로그래밍/C#

C#] 산술 연산자

by 곰나나 2024. 1. 12.

[산술 연산자]

1. 산술 연산자(Arithmetic Operator)

C#에서 제공하는 산술 연산자는 더하기(Add), 빼기(Subtract), 곱하기(multiply), 나누기(Divide), 나머지(Remainder, Modulus)의 수학적 연산을 하는데 사용된다.

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
31
32
33
34
35
36
37
38
using System;
 
class Arithmetic
{
    static void Main()
    {
        //& 덧셈 연산자
        int a = 10;
        int b = 5;
        int sum = a + b;
        Console.WriteLine("덧셈 결과: " + sum);
 
        //& 뺄셈 연산자
        int c = 8;
        int d = 3;
        int difference = c - d;
        Console.WriteLine("뺄셈 결과: " + difference);
 
        //& 곱셈 연산자
        int e = 4;
        int f = 6;
        int product = e * f;
        Console.WriteLine("곱셈 결과: " + product);
 
        //& 나눗셈 연산자
        int g = 15;
        int h = 2;
        int quotient = g / h;
        Console.WriteLine("나눗셈 결과: " + quotient);
 
        //& 나머지 연산자
        int i = 17;
        int j = 4;
        int remainder = i % j;
        Console.WriteLine("나머지 결과: " + remainder);
 
    }// Main
}// Arithmetic
cs

728x90

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

C#] 할당 연산자  (0) 2024.01.12
C#] 문자열 연결 연산자  (0) 2024.01.12
C#] 단항 연산자  (0) 2024.01.11
C#] 연산자  (0) 2024.01.11
C#] Convert 클래스의 메서드들을 사용하여 데이터 타입을 변환  (0) 2024.01.10