[백준] 10430 : 나머지 - Java

길 잃은 까마귀·2022년 9월 12일
0

https://www.acmicpc.net/problem/10430


  • 문제

  • 풀이
    복잡해 보일 수 있겠지만 사실 아직까지도 기본적인 사칙연산이다. 다만 계산순서를 고려해야 하기에 괄호를 신경써야 한다.

  • 코드
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println((a + b) % c);
		System.out.println(((a % c) + (b % c)) % c);
		System.out.println((a * b) % c);
		System.out.println(((a % c) * (b % c)) % c);
		sc.close();
	}
}
profile
코딩 고수가 될 사람

0개의 댓글