백준 10430 : 나머지

C# 2020. 11. 15. 22:11

(A+B)%C는 ((A%C) + (B%C))%C 와 같을까?

(A×B)%C는 ((A%C) × (B%C))%C 와 같을까?

세 수 A, B, C가 주어졌을 때, 위의 네 가지 값을 구하는 프로그램을 작성하시오.

첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000)
첫째 줄에 (A+B)%C, 둘째 줄에 ((A%C) + (B%C))%C, 셋째 줄에 (A×B)%C, 넷째 줄에 ((A%C) × (B%C))%C를 출력한다.

:: 성공

: 개선점 : 없음

using System;

namespace Print05
{
    class Program
    {
        static void Main(string[] args)
        {
            // :: Input
            string[] input = Console.ReadLine().Split(' ');
            // :: Parsing
            int a = Int32.Parse(input[0]);
            int b = Int32.Parse(input[1]);
            int c = Int32.Parse(input[2]);
            // :: Result
            Console.WriteLine("{0}", (a + b) % c);
            Console.WriteLine("{0}", ((a % c) + (b % c)) % c);
            Console.WriteLine("{0}", (a * b) % c);
            Console.WriteLine("{0}", ((a % c) * (b % c)) % c);
        }
    }
}

'C#' 카테고리의 다른 글

백준 1330 : 두 수 비교하기  (0) 2020.11.18
백준 2588 : 곱셈  (0) 2020.11.16
백준 10869 : 사칙연산  (0) 2020.11.14
백준 10998 : A×B  (0) 2020.11.13
백준 1008 : A/B  (0) 2020.11.12
블로그 이미지

RIsN

,

백준 10869 : 사칙연산

C# 2020. 11. 14. 22:33

두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오.

두 자연수 A와 B가 주어진다. (1 ≤ A, B ≤ 10,000)
첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A*B, 넷째 줄에 A/B, 다섯째 줄에 A%B를 출력한다.

:: 성공

: 개선점 : 없음

using System;

namespace Print05
{
    class Program
    {
        static void Main(string[] args)
        {
            // :: Input
            string[] input = Console.ReadLine().Split(' ');
            // :: Parsing
            int a = Int32.Parse(input[0]);
            int b = Int32.Parse(input[1]);
            // :: Result
            Console.WriteLine("{0}", a + b);
            Console.WriteLine("{0}", a - b);
            Console.WriteLine("{0}", a * b);
            Console.WriteLine("{0}", a / b);
            Console.WriteLine("{0}", a % b);
        }
    }
}

'C#' 카테고리의 다른 글

백준 2588 : 곱셈  (0) 2020.11.16
백준 10430 : 나머지  (0) 2020.11.15
백준 10998 : A×B  (0) 2020.11.13
백준 1008 : A/B  (0) 2020.11.12
백준 10172 : 개 // 성공  (0) 2020.11.07
블로그 이미지

RIsN

,

백준 10998 : A×B

C# 2020. 11. 13. 22:36

두 정수 A와 B를 입력받은 다음, A×B를 출력하는 프로그램을 작성하시오.

첫째 줄에 A와 B가 주어진다. (0 < A, B < 10)
첫째 줄에 A×B를 출력한다.

:: 성공

: 개선점 : 없음

using System;

namespace Print05
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            Console.WriteLine("{0}", Int32.Parse(input[0]) * Int32.Parse(input[1]));
        }
    }
}

'C#' 카테고리의 다른 글

백준 10430 : 나머지  (0) 2020.11.15
백준 10869 : 사칙연산  (0) 2020.11.14
백준 1008 : A/B  (0) 2020.11.12
백준 10172 : 개 // 성공  (0) 2020.11.07
백준 10171 : 고양이 // 성공  (0) 2020.11.06
블로그 이미지

RIsN

,