Home > Back-end >  Can you help me look at the code?
Can you help me look at the code?

Time:09-26

#include

Int IsPrime (int x) {
int i;
for(i=0; I<=x/2; I++);
If (x % I!=0) {
return 1;
}
The else {
return 0;
}
}
Void PrintPrime (int m, int n) {
int i;
For (I=m; I<=n; I++);
If (IsPrime (I)==0) {
Printf (" does not exist within the range of the prime ");
}
The else {printf (" % d ", IsPrime (I));
}
}
Int main () {
Int m, n;
Printf (" please enter the two positive integers: ");
The scanf (" % d % d ", & amp; M, & amp; N);
Printf (" % d ", PrintPrime (m, n));
Return 0
}

CodePudding user response:

You this program problem many
You don't understand what is the prime
I wrote a code, you see

 # include 
Int main ()
{
Int m, n, t, count, I, j;
The scanf (" % d ", & amp; T);
While (t -)
{
The scanf (" % d % d ", & amp; M, & amp; N);
If (m==n | | n==1)
{
Printf (" 0 \ n ");
}
The else
{
Count=0;
For (I=m; I<=n; I++)
{
For (j=2; J{
If (I % j==0)
{
break;
}
}
If (j==I)
{
count++;
}
}
Printf (" % d \ n ", count);
}
}
return 0;

}

CodePudding user response:

Printf (" % d ", PrintPrime (m, n)); PrintPrime return values are void you print what
Printf (" % d ", IsPrime (I)) that has been printed 1 what good print

CodePudding user response:

refer to the second floor bo_self_effacing response:
printf (" % d ", PrintPrime (m, n)); PrintPrime return values are void you print what
Printf (" % d ", IsPrime (I)) that has been printed 1 have nothing to print

To show you the topic the first function returns a value of 0 and 1 why requirements?
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:

 # include & lt; stdio.h> 

Int IsPrime (int x) {
int i;
For (I=2; I & lt;=x/2; I++)//a for loop structure you are wrong for (... ) {} you before is for (); .
{
If I==0) (x % {
return 0;
}
}
return 1;
}
{int PrintPrime (int m, int n)
int i;
int count=0;
For (I=m; I & lt;=n; I++)
{
If (IsPrime (I))
{
count++;
If (count % 5==0)
{
Printf (" % d \ n ", I);
}
The else
{
Printf (" % d ", I);
}
}
}
Return the count.
}
Int main () {
Int m, n;
Printf (" please enter the two positive integers: ");
Scanf_s (" % d % d ", & amp; M, & amp; N);
Int count=PrintPrime (m, n);
if (! The count) printf (" does not exist within the range of the prime ");.
While (1) getchar ();
return 0;
}

CodePudding user response:

#include

Int IsPrime (int x)
{
If (x==1)
return 0;
For (int I=2; I & lt; x; I++)
If (x % I==0)
{
return 0;
}
return 1;
}
Void PrintPrime (int m, int n)
{
int count=0;
For (int I=m; I & lt;=n; I++)
{
If (IsPrime (I))
{
Printf (" % d ", I);
count++;
}
}
if (! The count)
{
Printf (" no prime Numbers in the area ");
}
}
Int main ()
{
Int m, n;
Printf (" please enter the two positive integers: ");
The scanf (" % d, % d ", & amp; M, & amp; N);
PrintPrime (m, n);
return 0;
}

CodePudding user response:

reference 4 floor bo_self_effacing response:
 # include & lt; stdio.h> 

Int IsPrime (int x) {
int i;
For (I=2; I & lt;=x/2; I++)//a for loop structure you are wrong for (... ) {} you before is for (); .
{
If I==0) (x % {
return 0;
}
}
return 1;
}
{int PrintPrime (int m, int n)
int i;
int count=0;
For (I=m; I & lt;=n; I++)
{
If (IsPrime (I))
{
count++;
If (count % 5==0)
{
Printf (" % d \ n ", I);
}
The else
{
Printf (" % d ", I);
}
}
}
Return the count.
}
Int main () {
Int m, n;
Printf (" please enter the two positive integers: ");
Scanf_s (" % d % d ", & amp; M, & amp; N);
Int count=PrintPrime (m, n);
if (! The count) printf (" does not exist within the range of the prime ");.
While (1) getchar ();
return 0;
}

Why the compiler work for a long time all cannot replicate this code

CodePudding user response:

refer to 6th floor ycm151 response:
Quote: refer to 4th floor bo_self_effacing response:
 # include & lt; stdio.h> 

Int IsPrime (int x) {
int i;
For (I=2; I & lt;=x/2; I++)//a for loop structure you are wrong for (... ) {} you before is for (); .
{
If I==0) (x % {
return 0;
}
}
return 1;
}
{int PrintPrime (int m, int n)
int i;
int count=0;
For (I=m; I & lt;=n; I++)
{
If (IsPrime (I))
{
count++;
If (count % 5==0)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related