-->
当前位置:首页 > 题库

PROGRAMMING:C programming experiment 4-5 prime search task 2

Luz5年前 (2021-05-10)题库412
Prime numbers are positive integers that cannot be divisible by integers other than 1 and itself. According to this definition, * * - negative numbers, 0 and 1 are not prime numbers * *, while 17 is prime because it cannot be divisible by any integer between 2 and 16 except 1 and 17.
Use the integer between 2 and sqrt (m) (the square root of M) to test the quotient
-If M can be divided by an integer in the above range (the remainder is 0), then M is not a prime;
-If each integer between the above ranges cannot divide m, then M is a prime.
According to the above algorithm to write the function isprime (), input an integer m from the keyboard to determine whether M is a prime.
###Function interface definition
```
int IsPrime(int m);
```
Where ` m 'is the number entered by the user.
If M is a prime, the function returns 1; Otherwise, the function returns 0
###Input format:
The user enters any positive integer M.
###Output format:
If M is a prime number, it will be output in the format of% d is a prime number, which is a prime number
Otherwise, output the number in the format of% d is not a prime number, which is not a prime number.
###Input example:
Here is a set of inputs. For example:
```in
three
```
###Output example:
The corresponding output is given here. For example:
```out
3 is a prime number
```
###Input example 2:
```in
one
```
###Output example 2:
```out
1 is not a prime number
```






answer:If there is no answer, please comment