C language essence-identify prime numbers, essence identify prime numbers

Source: Internet
Author: User

C language essence-identify prime numbers, essence identify prime numbers
# Include <math. h>
# Include <stdio. h>
Int IsPrimeNumber (int number );
Int main ()
{
Int n, ret;
Printf ("Input n :");
Scanf ("% d", & n );
Ret = IsPrimeNumber (n );
 
If (ret! = 0) // 01
{
Printf ("% d is a prime number \ n", n );
}
Else
{
Printf ("% d is not a prime number \ n", n );
}
 
Return 0;
}
 
// Function: determines whether the number is a prime number. The function returns a non-zero value, indicating that the number is a prime number. Otherwise, the number is not a prime number.
Int IsPrimeNumber (int number)
{
Int I;

If (number <= 1) return 0; // negative number, 0, and 1 are not prime numbers
For (I = 2; I <= sqrt (number); I ++)
{
If (number & I = 0) // divisible, not a prime number
Return 0;
}
 
Return 1;
}

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.