@@@@ 10.13 @@@@
(산술 연산)
산술 연산은 일반적인 사칙연산과 유사하며 변수에 바로 계산이 가능하다.
증감 연산을 제외한 일반연산들은 변수에 다시 할당해야 값이 저장됨
+ = 더하기
int x = 10;
int result;
result = x + 3; // result : 13
- = 빼기
int x = 10;
int result;
result = x - 5; // result : 5
* = 곱하기
int x = 10;
int result;
result = x * 2; // result : 20
/ = 나누기
% = 나머지
int x = 17;
int result_1;
int result_2;
result_1 = x / 5; // result_1 : 3
result_2 = x % 5; // result_2 : 2
( /연산보다 *연산이 더빠름)
++ = 증가
-- = 감소
int x = 10;
x++; // x : 11
int y = 10;
y--; // y : 9
int x = 10;
Console.WriteLine(x++); // 10
Console.WriteLine(x); // 11
int y = 10;
Console.WriteLine(++y); // 11
Console.WriteLine(y); // 11
(산술 연산 - 문자열)
산술연산은 숫자의 계산 말고도 문자도 계산가능 ( +연산 활용가능)
string hello = "안녕!";
string bye = "잘가!";
string result = hello + bye;
Console.WriteLine(result);
실행 결과
안녕!잘가!
변수와 문자열도 연산가능
string hello = "안녕!";
string result = hello + "잘가!";
Console.WriteLine(result);
실행 결과
안녕!잘가!
문자와 숫자도 가능
int year = 9999;
string result = year + "년 입니다.";
Console.WriteLine(result);
실행 결과
9999년 입니다.
(논리 연산 - 같음 연산자, 비교 연산자 )
논리 연산은 계산이 아닌 판단하는것 (같은지, 다른지, 큰지, 작은지)
같음, 비교 연산자는 bool 형태로 나타남
== 같다
!= 다르다
int x = 10;
bool Same = x == 10;
// true
int x = 10;
bool Same = x != 10;
// false
> >=
< <=
int x = 23;
bool Big = x > 19;
// true
int x = 23;
bool Big = x < 19;
// false
(자료형 - bool)
bool은 ture 와 false 결과가 나온다.
이와 같은 판단을 하면 제어문에서 핵심적인 기능을 하는 자료로 활용
특정한 상황이 되었을때 어떻게 진행될지 판단근거가 되는 것이 bool 자료형
'2023_10_12~30 (c#기초)' 카테고리의 다른 글
10.19 (c# 기초) (0) | 2023.10.19 |
---|---|
10.18 (c# 기초) (0) | 2023.10.18 |
10.16 (c#기초) (0) | 2023.10.16 |
10.12(c#기초) (0) | 2023.10.12 |