프로그래밍/C#
C#] 산술 연산자
곰나나
2024. 1. 12. 15:54
[산술 연산자]
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