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

[C#] Math 클래스 (Pow, Sqrt, Abs, Round, Ceiling, Floor, Max, Min)

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

namespace MyFirstProgram
{
    internal class Program
    {

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

            double xx = 3;
            double xxx = Math.Pow(xx, 4);
            Console.WriteLine(xxx); // 81

            double yy = Math.Sqrt(Math.Sqrt(xxx));
            Console.WriteLine(yy); // 9

            double cc = Math.Abs(-123);
            Console.WriteLine(cc); // 123

            double dd = Math.Round(3.14);
            Console.WriteLine(dd); // 3

            double ee = Math.Ceiling(3.14);
            Console.WriteLine(ee); // 4

            double ff = Math.Floor(3.99);
            Console.WriteLine(ff); // 3

            double gg = 5;
            double gggg = Math.Max(gg, 100);
            Console.WriteLine(gggg); // 100

            double hh = Math.Min(gggg, 10);
            Console.WriteLine(hh); // 10

        }
    }
}
728x90