본문 바로가기
프로그램/C# 1000제

C# 10제] C# 프로그래밍 입문 CHAPTER 2. p106 2.12 (10) 무한 연산의 값을 계산하는 프로그램을 작성하시오.

by 건티 2021. 7. 24.
728x90

문제]

다음과 같은 무한 연산(infinite arithmetic)의 값을 계산해서 출력하는 C# 프로그램을 작성하시오.

① +∞ + +∞

② +∞ - +∞

③ -∞ + -∞

④ -∞ - -∞

⑤ 0.0 / 0.0

⑥ double.MaxValue / +∞

 

참고풀이]

using System;
using System.Collections.Generic;
using System.Text;

namespace Chapter2
{
    class P106_2_12_10
    {
        public static void Main()
        {
            Console.Write("① +∞ + +∞ : ");
            Console.WriteLine((double.PositiveInfinity + double.PositiveInfinity));
            Console.Write("② +∞ - +∞ : ");
            Console.WriteLine((double.PositiveInfinity - double.PositiveInfinity));
            Console.Write("③ -∞ + -∞ : ");
            Console.WriteLine((double.NegativeInfinity + double.NegativeInfinity));
            Console.Write("④ -∞ - -∞ : ");
            Console.WriteLine((double.NegativeInfinity - double.NegativeInfinity));
            Console.Write("⑤ 0.0 / 0.0 : ");
            Console.WriteLine((0.0/0.0));
            Console.Write("⑥ double.MaxValue / +∞ : ");
            Console.WriteLine((double.MaxValue / double.PositiveInfinity));
        }
    }
}

 

참고풀이 결과]

 

 

 

대한민국의 아름다운 영토, 독도의 가을

 

반응형

댓글