Home > Back-end >  (C) programming implementation, will be to display all the prime Numbers between 1-1000. Who is the
(C) programming implementation, will be to display all the prime Numbers between 1-1000. Who is the

Time:12-10

1., programming implementation, will be displayed all super prime Numbers between 1-1000, who is the super prime number is a prime, and itself as the number of primes,


Asked to use a custom function, this experiment I see for a long time, only to find the prime Numbers within 1000, I learned C is not very good, big help

CodePudding user response:

 # include & lt; stdio.h> 
#include

Int is_prime (int num);

Int main (void)
{

int i;
Int TMP.

For (I=1; I & lt; 1000; I +=2) {
//printf (" I=% d \ n ", I);
TMP=I;
If (is_prime (TMP)) {
If (TMP & lt; 10) {
Printf (" % d ", I);
continue;
}
While (TMP) {
{if (is_prime (TMP % 10))
TMP/=10;
continue;
}
break;
}
If (TMP==0)
Printf (" % d ", I);
}
}

return 0;

}

Int is_prime (int num)
{
int i;

If (num & lt; 2)
return 0;

Int size=(int) SQRT (num);
For (I=2; I & lt; The size of + 1; I++)
If (num % I==0)
return 0;

return 1;
}


For your reference ~
  • Related