The so-called primes are those numbers that cannot be divisible by any integer except 1 and itself. For example, 17 is the prime number, because it is not the same as any integer divisible by 2~16. Therefore, determine whether an integer nnum is a prime number. It is only necessary to remove the nnum from each integer between the 2~nnum-1. If none of them are divisible, then nnum is a prime number.
Here we can also use a simple way to simply be 2~√m between each integer to remove it.
#include <stdio.h> #include <math.h>int isprimenum (int nnum); Int main () { int nNum; int nFlag = 0; printf ("Enter a number to determine if prime: \ n"); &NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d", &nnum); if (Nflag = isprimenum (nnum)) printf ("This is a prime number.") \ n "); else printf (" This is not a prime number.) \ n "); return 0;} Int isprimenum (Int nnum) { int nflag = 0; int ntmp; int i; ntmp=sqrt (NNum); for (i=2;i<=ntmp;i++) if (nNum%i==0) break; if (I>NTMP) & Nbsp; return nflag = 1; else retrun nflag = 0;}
How to determine if the prime number and the primes in a segment are