Machineboy空
자주 쓰는 Math Library 함수 본문
제곱 관련
- Math.Pow(,)
int result = Math.Pow(2,3);
// 2^3 = 8 즉, 2의 3제곱
- Math.Sqrt()
int result = Math.Sqrt(16);
// 16의 제곱근 = 4
절댓값
- Math.Abs()
int result = Math.Abs(-10); // 10
반올림, 반내림 관련
- Math.Ceiling()
주어진 값보다 크거나 같은 가장 작은 정수 반환.
double result = Math.Ceiling(2.3); // 3
- Math.Floor()
주어진 값보다 작거나 같은 가장 큰 정수 반환.
double result = Math.Floor(2.3); // 2
- Math.Round()
0.5 기준으로 주어진 값 반올림
double result = Math.Round(2.3); // 2
double result = Math.Round(2.5); // 3
double result = Math.Round(2.7); // 3
최대 최소 관련
- Math.Max()
int result = Math.Max(3,7); // 7
- Math.Min()
int result = Math.Min(3,7); // 3
'언어 > C#' 카테고리의 다른 글
헷갈리는 2차원 배열, 리스트 정리 (0) | 2025.03.18 |
---|---|
NullReferenceException (0) | 2025.03.12 |
C# 문제 풀이 빠른 입출력 (0) | 2025.03.11 |
C# 메소드 오버로딩(Overloading) (0) | 2025.02.28 |
C# 자원 해제(Resource Clean up) try~catch, finally, using Dipose() (0) | 2025.02.26 |