C/C++ Programming Learning-Week 8 ③ Divide problem

Topic link

Title description

Judging whether a number can be divisible by another integer is a very simple problem. Generally, a modular operation can be done. The lazy Xiaomeng still doesn't want to do it by himself, so if you find you to write the code for him, you can help him.

Input format The
input consists of two integers M and N separated by spaces (1≤M, N≤500).

Output format The
output consists of one line. If M is divisible by N, it outputs YES, otherwise it outputs NO (the result is case sensitive).

Sample Input

21 7

Sample Output

YES

Ideas

Judge whether a number can be divisible by another integer, if M can be divisible by N, output YES, otherwise output NO. Divide is a modulo% operation, and a remainder of 0 means that it can be divided evenly. I have written similar questions before, so I won’t say more.

C++ code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int m, n;
	while(cin >> m >> n)
	{
    
    
		if(m % n == 0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113079844