Home > Back-end >  For interval primes
For interval primes

Time:09-27

Subject for realization of a simple function of prime number and the use of the function to determine whether a given interval integer prime Numbers, and output function, according to a row of five

Prime: only positive integer divisible by 1 and itself, is not a prime number 1, 2 is a prime number

Function interface definition:

Int IsPrime (int x);

M void PrintPrime (int, int n);

IsPrime () function, when x is a prime number return 1, otherwise it returns 0. Function PrintPrime output range within [m, n] all prime Numbers, according to a row of five output, if not a prime number in this interval, then output "does not exist within the range of the prime",

Requirement: the main function of the input of two positive integers m and n, the calling function PrintPrime output, IsPrime function calls a function PrintPrime need to decide in the interval [m, n] whether an integer is prime,

CodePudding user response:

 int main () 
{
Int m;
Int a, I;
Printf (" input "m:");
The scanf (" % d ", & amp; M);
for(i=2; i{
If (m % I==0)
{
a++;
}
}

If (a==0)
Printf (" y ");
The else
Printf (" n ");
return 0;
}


I have written a prime number, you should be able to think out
  • Related