How to determine if the prime number and the primes in a segment are

Source: Internet
Author: User

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&GT;NTMP)  & Nbsp;      return nflag = 1;    else         retrun nflag = 0;}



How to determine if the prime number and the primes in a segment are

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.