Use the C language to verify the godebach conjecture (defined as the int type)

Source: Internet
Author: User

Godbach conjecture:

If an even number greater than 6, the sum of two prime numbers can be written. It is called in line with the godebach conjecture.

# Include
 
  
# Include
  
   
///
   /// Determine whether a number is a prime number //////
   Number of items to be determined///
   
    
If yes, true is returned. Otherwise, false is returned.
   Static bool IsPrimeNumber (int intNum) {bool blFlag = true; // identify whether it is a prime number if (intNum = 1 | intNum = 2) // determine whether the input number is 1 or 2 blFlag = true; // assign else {int sqr = (int) (sqrt (double) intNum) to the bool type variable )); // perform the square operation for the number to be judged (int I = sqr; I> = 2; I --) // cyclically {if (intNum % I = 0) from the number after the start // perform the remainder operation on the number to be judged and the specified number {blFlag = false; // if the remainder is 0, it is not a prime number} return blFlag; // return bool variable }///
   /// Determine whether a number conforms to the godebach conjecture //////
   Number of items to be determined///
   
    
If yes, true is returned. Otherwise, false is returned.
   Static bool ISGDBHArith (int intNum) {bool blFlag = false; // identify whether it meets the godebach conjecture if (intNum % 2 = 0 & intNum> 6) // judge the number to be judged {for (int I = 1; I <= intNum/2; I ++) {bool bl1 = IsPrimeNumber (I ); // determine whether I is a prime number bool bl2 = IsPrimeNumber (intNum-I); // determine whether intNum-I is a prime number if (bl1 & bl2) {// Output Equation printf ("% d = % d + % d \ n", intNum, I, intNum-I); blFlag = true; // break; // conforms to the godebach conjecture }}return blFlag; // returns the bool variable} void main (){ Int a = 0; printf ("enter an even number greater than 6: \ n"); scanf_s ("% d", & a, 10 ); bool blFlag = ISGDBHArith (a); // you can determine whether the result is consistent with the pair of prime numbers (if (blFlag) {printf ("% d. ", A) ;}getchar (); getchar ();}
  
 


Related Article

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.