C language classic algorithm example 5: verify Goldbach's conjecture

insert image description here

1. Problem description

1.1 What is Goldbach's conjecture

Goldbach proposed the following conjecture in a letter to Euler in 1742: any integer greater than 2 can be written as the sum of three prime numbers. But Goldbach himself couldn't prove it, so he wrote to ask Euler, a famous mathematician, to help him prove it, but Euler couldn't prove it until his death. Because the convention of "1 is also a prime number" is no longer used in the mathematics circle today, the modern statement of the original conjecture is: any integer greater than 5 can be written as the sum of three prime numbers. (n>5: When n is an even number, n=2+(n-2), n-2 is also an even number, which can be decomposed into the sum of two prime numbers; when n is an odd number, n=3+(n-3), n-3 is also an even number and can be decomposed into the sum of two prime numbers) Euler also proposed another equivalent version in his reply, that is, any even number greater than 2 can be written as the sum of two prime numbers. A common conjecture statement today is Euler's version. The proposition "any sufficiently large even number can be expressed as the sum of a number whose prime factors do not exceed a and another number whose prime factors do not exceed b" is written as "a+b". In 1966, Chen Jingrun proved that "1+2" ​​was established, that is, "any sufficiently large even number can be expressed as the sum of two prime numbers, or the sum of a prime number and a semi-prime number".

1.2, what is a semi-prime number

  • what is a semiprime

The natural number obtained by the product of two prime numbers
If a natural number can be expressed in the form of the product of two prime numbers, this natural number is called a semi-prime number (also known as a semi-prime number, a quadratic almost prime number).

  • For example, some of the numbers below are semi-prime.

4,6,9,10,14,15,21,22,25,26,33,34,35,38,39,46,49,51,55,57,58,62,65,69,74,77,82,85,86,87,91,93,94,95,106,111,115,118,119,121,122,123,129,133,134,141,142.

1.3. Description of the problem in this article

To verify Goldbach's conjecture,
the description of the problem
is as follows

  1. Any sufficiently large even number can be expressed as the sum of two prime numbers, or the sum of a prime number and a semi-prime number.
  2. The even number input is an even number greater than 6.
  3. Verify Goldbach's conjecture for numbers between 1 and 100.
  4. The program adopts the idea of ​​function modularization.

2. Algorithm example compilation environment

The compilation environment of the C language classic algorithm example in this article uses the integrated development environment: Visual Studio 2019
insert image description here

insert image description here

The link to the official website of Visual Studio 2019 is as follows

Visual Studio 2019 official website link
insert image description here

The features of the Visual Studio 2019 integrated development environment are

  1. Visual Studio 2019 installs the Live Share code collaboration service by default.
  2. New welcome window to help users write code quickly, improved search functionality, general performance improvements.
  3. Visual Studio IntelliCode AI Help.
  4. Better Python virtualization and Conda support.
  5. And support for .NET Core 3.0 projects including WinForms and WPF, etc.

3. The implementation process of the algorithm example

3.1, including the header file

Include the header file code as follows

#pragma once

// 包含头文件
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
  • The C language header files that will be used include recent years.

3.2. Declare variables

The variable declaration code is as follows

int a = 0;
  • The variable a is declared.
  • Used as an input variable.

3.3. Enter an even number greater than 6

Enter an even code greater than 6 as shown below

	printf("输入一个大于 6 的偶数:");

    scanf("%d", &a);
    printf("\n");
  • Declare related variables min, max, row, col, n;

3.4. Verify Goldbach's conjecture for the input numbers

  • The verification of Goldbach's conjecture on the input numbers is written in the form of a function.

The verification code for Goldbach's conjecture on the input number is as follows

  1. Declaration of a verification function that performs Goldbach's conjecture.
/// <summary>
/// 对输入的数字进行哥德巴赫猜想的验证
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool ISGDBHArith(int intNum);
  1. Definition of a verification function for Goldbach's conjecture.
/// <summary>
/// 对输入的数字进行哥德巴赫猜想的验证
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool ISGDBHArith(int intNum)
{
    
    
    bool blFlag = false;							    // 标识是否符合哥德巴赫猜想 
    if (intNum % 2 == 0 && intNum > 6)			        // 对要判断的数字进行判断 
    {
    
    
        for (int i = 1; i <= intNum / 2; i++)
        {
    
    
            bool bl1 = IsPrimeNumber(i);			    // 判断i 是否为素数 
            bool bl2 = IsPrimeNumber(intNum - i);		// 判断 intNum-i 是否为素数 

            if (bl1 & bl2)
            {
    
    
                //输出等式 
                printf("%d = %d + %d\n", intNum, i, intNum - i);
                blFlag = true;
                // 符合哥德巴赫猜想 
            }
        }
    }

    return blFlag;							            // 返回bool 型变量 
}
  • Verify Goldbach's conjecture on the input numbers.
  • The function returns a variable of type bool: blFlag.
    insert image description here

3.5. Determine whether the input number is a prime number.

  • Determine whether the input number is a prime number, written in the form of a function.

Determine whether the input number is a prime number, the code is as follows

  1. A function declaration to determine whether the input number is a prime number.
/// <summary>
/// 判断输入的数字是否为素数。
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool IsPrimeNumber(int intNum);
  1. Function definition to determine whether the input number is a prime number.
/// <summary>
/// 判断输入的数字是否为素数。
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool IsPrimeNumber(int intNum)
{
    
    
    bool blFlag = true;						    // 标识是否是素数 

    if (intNum == 1 || intNum == 2)				// 判断输入的数字是否是 1 或者 2 
    {
    
    
        blFlag = true;						    // 为bool 类型变量赋值 
    }
    else
    {
    
    
        int sqr = (int)(sqrt((double)intNum));	// 对要判断的数字进行开方运算 

        for (int i = sqr; i >= 2; i--)			// 从开方后的数进行循环 
        {
    
    
            if (intNum % i == 0)				// 对要判断的数字和指定数字进行求余运算 
            {
    
    
                blFlag = false;				    // 如果余数为 0,说明不是素数 
            }
        }
    }

    return blFlag;							    // 返回bool 型变量 
}
  • Determines whether the input number is a prime number.
  • The function returns a variable of type bool: blFlag.

Press F5 to compile, and the debugging results are as follows.

insert image description here

  • The data we input into the array can be output correctly.

3.6. Judgment of Goldbach's conjecture on the input numbers

The judgment code for Goldbach's conjecture on the input number is as follows

	if (blFlag)
    {
    
    
        printf("\n%d:能写成两个素数的和,所以其符合哥德巴赫猜想。\n\n", a);
    }
    else
    {
    
    
        printf("\n%d:不能写成两个素数的和,所以其不符合哥德巴赫猜想。\n\n", a);
    }
  • If the input number can be written as the sum of two prime numbers, it conforms to Goldbach's conjecture.
  • If the input number cannot be written as the sum of two prime numbers, Goldbach's conjecture is not met.

Press F5 to compile, and the debugging results are as follows.

insert image description here

3.7. Determine whether the number 1-100 conforms to Goldbach's conjecture.

  • Judging whether the number 1-100 conforms to Goldbach's conjecture is written in a function.

The code to judge whether the number 1-100 conforms to Goldbach's conjecture is as follows.

  1. A function statement that judges whether a number 1-100 satisfies Goldbach's conjecture.
 /// <summary>
/// 判断数字1-100是否符合哥德巴赫猜想。
/// </summary>
void digitJudge();
  1. Determine whether the number 1-100 conforms to the function definition of Goldbach's conjecture.
/// <summary>
/// 判断数字1-100是否符合哥德巴赫猜想。
/// </summary>
void digitJudge()
{
    
    

    for (int i = 1; i <= 100; i++)
    {
    
    
        bool blFlag = ISGDBHArith(i);				        // 判断是否符合哥德巴赫猜想 

        if (blFlag)
        {
    
    
            printf("\n%d:能写成两个素数的和,所以其符合哥德巴赫猜想。\n\n", i);
        }
        else
        {
    
    
            printf("\n%d:不能写成两个素数的和,所以其不符合哥德巴赫猜想。\n\n", i);
        }

        printf("\n");
    }
}
  • The way to use for loop.
  • Determine whether the number 1-100 conforms to Goldbach's conjecture.

Press F5 to compile, and the debugging results are as follows.

insert image description here

输入一个大于 6 的偶数:24

24 = 1 + 23
24 = 5 + 19
24 = 7 + 17
24 = 11 + 13

24:能写成两个素数的和,所以其符合哥德巴赫猜想。


1:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



2:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



3:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



4:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



5:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



6:不能写成两个素数的和,所以其不符合哥德巴赫猜想。



7:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


8 = 1 + 7
8 = 3 + 5

8:能写成两个素数的和,所以其符合哥德巴赫猜想。



9:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


10 = 3 + 7
10 = 5 + 5

10:能写成两个素数的和,所以其符合哥德巴赫猜想。



11:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


12 = 1 + 11
12 = 5 + 7

12:能写成两个素数的和,所以其符合哥德巴赫猜想。



13:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


14 = 1 + 13
14 = 3 + 11
14 = 7 + 7

14:能写成两个素数的和,所以其符合哥德巴赫猜想。



15:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


16 = 3 + 13
16 = 5 + 11

16:能写成两个素数的和,所以其符合哥德巴赫猜想。



17:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


18 = 1 + 17
18 = 5 + 13
18 = 7 + 11

18:能写成两个素数的和,所以其符合哥德巴赫猜想。



19:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


20 = 1 + 19
20 = 3 + 17
20 = 7 + 13

20:能写成两个素数的和,所以其符合哥德巴赫猜想。



21:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


22 = 3 + 19
22 = 5 + 17
22 = 11 + 11

22:能写成两个素数的和,所以其符合哥德巴赫猜想。



23:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


24 = 1 + 23
24 = 5 + 19
24 = 7 + 17
24 = 11 + 13

24:能写成两个素数的和,所以其符合哥德巴赫猜想。



25:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


26 = 3 + 23
26 = 7 + 19
26 = 13 + 13

26:能写成两个素数的和,所以其符合哥德巴赫猜想。



27:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


28 = 5 + 23
28 = 11 + 17

28:能写成两个素数的和,所以其符合哥德巴赫猜想。



29:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


30 = 1 + 29
30 = 7 + 23
30 = 11 + 19
30 = 13 + 17

30:能写成两个素数的和,所以其符合哥德巴赫猜想。



31:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


32 = 1 + 31
32 = 3 + 29
32 = 13 + 19

32:能写成两个素数的和,所以其符合哥德巴赫猜想。



33:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


34 = 3 + 31
34 = 5 + 29
34 = 11 + 23
34 = 17 + 17

34:能写成两个素数的和,所以其符合哥德巴赫猜想。



35:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


36 = 5 + 31
36 = 7 + 29
36 = 13 + 23
36 = 17 + 19

36:能写成两个素数的和,所以其符合哥德巴赫猜想。



37:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


38 = 1 + 37
38 = 7 + 31
38 = 19 + 19

38:能写成两个素数的和,所以其符合哥德巴赫猜想。



39:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


40 = 3 + 37
40 = 11 + 29
40 = 17 + 23

40:能写成两个素数的和,所以其符合哥德巴赫猜想。



41:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


42 = 1 + 41
42 = 5 + 37
42 = 11 + 31
42 = 13 + 29
42 = 19 + 23

42:能写成两个素数的和,所以其符合哥德巴赫猜想。



43:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


44 = 1 + 43
44 = 3 + 41
44 = 7 + 37
44 = 13 + 31

44:能写成两个素数的和,所以其符合哥德巴赫猜想。



45:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


46 = 3 + 43
46 = 5 + 41
46 = 17 + 29
46 = 23 + 23

46:能写成两个素数的和,所以其符合哥德巴赫猜想。



47:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


48 = 1 + 47
48 = 5 + 43
48 = 7 + 41
48 = 11 + 37
48 = 17 + 31
48 = 19 + 29

48:能写成两个素数的和,所以其符合哥德巴赫猜想。



49:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


50 = 3 + 47
50 = 7 + 43
50 = 13 + 37
50 = 19 + 31

50:能写成两个素数的和,所以其符合哥德巴赫猜想。



51:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


52 = 5 + 47
52 = 11 + 41
52 = 23 + 29

52:能写成两个素数的和,所以其符合哥德巴赫猜想。



53:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


54 = 1 + 53
54 = 7 + 47
54 = 11 + 43
54 = 13 + 41
54 = 17 + 37
54 = 23 + 31

54:能写成两个素数的和,所以其符合哥德巴赫猜想。



55:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


56 = 3 + 53
56 = 13 + 43
56 = 19 + 37

56:能写成两个素数的和,所以其符合哥德巴赫猜想。



57:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


58 = 5 + 53
58 = 11 + 47
58 = 17 + 41
58 = 29 + 29

58:能写成两个素数的和,所以其符合哥德巴赫猜想。



59:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


60 = 1 + 59
60 = 7 + 53
60 = 13 + 47
60 = 17 + 43
60 = 19 + 41
60 = 23 + 37
60 = 29 + 31

60:能写成两个素数的和,所以其符合哥德巴赫猜想。



61:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


62 = 1 + 61
62 = 3 + 59
62 = 19 + 43
62 = 31 + 31

62:能写成两个素数的和,所以其符合哥德巴赫猜想。



63:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


64 = 3 + 61
64 = 5 + 59
64 = 11 + 53
64 = 17 + 47
64 = 23 + 41

64:能写成两个素数的和,所以其符合哥德巴赫猜想。



65:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


66 = 5 + 61
66 = 7 + 59
66 = 13 + 53
66 = 19 + 47
66 = 23 + 43
66 = 29 + 37

66:能写成两个素数的和,所以其符合哥德巴赫猜想。



67:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


68 = 1 + 67
68 = 7 + 61
68 = 31 + 37

68:能写成两个素数的和,所以其符合哥德巴赫猜想。



69:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


70 = 3 + 67
70 = 11 + 59
70 = 17 + 53
70 = 23 + 47
70 = 29 + 41

70:能写成两个素数的和,所以其符合哥德巴赫猜想。



71:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


72 = 1 + 71
72 = 5 + 67
72 = 11 + 61
72 = 13 + 59
72 = 19 + 53
72 = 29 + 43
72 = 31 + 41

72:能写成两个素数的和,所以其符合哥德巴赫猜想。



73:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


74 = 1 + 73
74 = 3 + 71
74 = 7 + 67
74 = 13 + 61
74 = 31 + 43
74 = 37 + 37

74:能写成两个素数的和,所以其符合哥德巴赫猜想。



75:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


76 = 3 + 73
76 = 5 + 71
76 = 17 + 59
76 = 23 + 53
76 = 29 + 47

76:能写成两个素数的和,所以其符合哥德巴赫猜想。



77:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


78 = 5 + 73
78 = 7 + 71
78 = 11 + 67
78 = 17 + 61
78 = 19 + 59
78 = 31 + 47
78 = 37 + 41

78:能写成两个素数的和,所以其符合哥德巴赫猜想。



79:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


80 = 1 + 79
80 = 7 + 73
80 = 13 + 67
80 = 19 + 61
80 = 37 + 43

80:能写成两个素数的和,所以其符合哥德巴赫猜想。



81:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


82 = 3 + 79
82 = 11 + 71
82 = 23 + 59
82 = 29 + 53
82 = 41 + 41

82:能写成两个素数的和,所以其符合哥德巴赫猜想。



83:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


84 = 1 + 83
84 = 5 + 79
84 = 11 + 73
84 = 13 + 71
84 = 17 + 67
84 = 23 + 61
84 = 31 + 53
84 = 37 + 47
84 = 41 + 43

84:能写成两个素数的和,所以其符合哥德巴赫猜想。



85:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


86 = 3 + 83
86 = 7 + 79
86 = 13 + 73
86 = 19 + 67
86 = 43 + 43

86:能写成两个素数的和,所以其符合哥德巴赫猜想。



87:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


88 = 5 + 83
88 = 17 + 71
88 = 29 + 59
88 = 41 + 47

88:能写成两个素数的和,所以其符合哥德巴赫猜想。



89:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


90 = 1 + 89
90 = 7 + 83
90 = 11 + 79
90 = 17 + 73
90 = 19 + 71
90 = 23 + 67
90 = 29 + 61
90 = 31 + 59
90 = 37 + 53
90 = 43 + 47

90:能写成两个素数的和,所以其符合哥德巴赫猜想。



91:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


92 = 3 + 89
92 = 13 + 79
92 = 19 + 73
92 = 31 + 61

92:能写成两个素数的和,所以其符合哥德巴赫猜想。



93:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


94 = 5 + 89
94 = 11 + 83
94 = 23 + 71
94 = 41 + 53
94 = 47 + 47

94:能写成两个素数的和,所以其符合哥德巴赫猜想。



95:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


96 = 7 + 89
96 = 13 + 83
96 = 17 + 79
96 = 23 + 73
96 = 29 + 67
96 = 37 + 59
96 = 43 + 53

96:能写成两个素数的和,所以其符合哥德巴赫猜想。



97:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


98 = 1 + 97
98 = 19 + 79
98 = 31 + 67
98 = 37 + 61

98:能写成两个素数的和,所以其符合哥德巴赫猜想。



99:不能写成两个素数的和,所以其不符合哥德巴赫猜想。


100 = 3 + 97
100 = 11 + 89
100 = 17 + 83
100 = 29 + 71
100 = 41 + 59
100 = 47 + 53

100:能写成两个素数的和,所以其符合哥德巴赫猜想。


请按任意键继续. . .

4. The complete code of the classic algorithm example program

The complete code of the classic algorithm example program is as follows

4.1, main.h file

#pragma once

// 包含头文件
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

/// <summary>
/// 判断数字1-100是否符合哥德巴赫猜想。
/// </summary>
void digitJudge();

/// <summary>
/// 对输入的数字进行哥德巴赫猜想的验证
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool ISGDBHArith(int intNum);


/// <summary>
/// 判断输入的数字是否为素数。
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool IsPrimeNumber(int intNum);

4.2, main.c file

#define _CRT_SECURE_NO_WARNINGS

#include "Main.h"


/// <summary>
/// 主函数
/// </summary>
/// <returns>返回0</returns>
int main()
{
    
    
    system("color 3E");

    int a = 0;

    printf("输入一个大于 6 的偶数:");

    scanf("%d", &a);
    printf("\n");

    bool blFlag = ISGDBHArith(a);				        // 判断是否符合哥德巴赫猜想 

    if (blFlag)
    {
    
    
        printf("\n%d:能写成两个素数的和,所以其符合哥德巴赫猜想。\n\n", a);
    }
    else
    {
    
    
        printf("\n%d:不能写成两个素数的和,所以其不符合哥德巴赫猜想。\n\n", a);
    }

    digitJudge();

    system("pause");
    return 0;
}

/// <summary>
/// 判断数字1-100是否符合哥德巴赫猜想。
/// </summary>
void digitJudge()
{
    
    

    for (int i = 1; i <= 100; i++)
    {
    
    
        bool blFlag = ISGDBHArith(i);				        // 判断是否符合哥德巴赫猜想 

        if (blFlag)
        {
    
    
            printf("\n%d:能写成两个素数的和,所以其符合哥德巴赫猜想。\n\n", i);
        }
        else
        {
    
    
            printf("\n%d:不能写成两个素数的和,所以其不符合哥德巴赫猜想。\n\n", i);
        }

        printf("\n");
    }
}

/// <summary>
/// 对输入的数字进行哥德巴赫猜想的验证
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool ISGDBHArith(int intNum)
{
    
    
    bool blFlag = false;							    // 标识是否符合哥德巴赫猜想 
    if (intNum % 2 == 0 && intNum > 6)			        // 对要判断的数字进行判断 
    {
    
    
        for (int i = 1; i <= intNum / 2; i++)
        {
    
    
            bool bl1 = IsPrimeNumber(i);			    // 判断i 是否为素数 
            bool bl2 = IsPrimeNumber(intNum - i);		// 判断 intNum-i 是否为素数 

            if (bl1 & bl2)
            {
    
    
                //输出等式 
                printf("%d = %d + %d\n", intNum, i, intNum - i);
                blFlag = true;
                // 符合哥德巴赫猜想 
            }
        }
    }

    return blFlag;							            // 返回bool 型变量 
}


/// <summary>
/// 判断输入的数字是否为素数。
/// </summary>
/// <param name="intNum">输入的数字</param>
/// <returns>blFlag</returns>
static bool IsPrimeNumber(int intNum)
{
    
    
    bool blFlag = true;						    // 标识是否是素数 

    if (intNum == 1 || intNum == 2)				// 判断输入的数字是否是 1 或者 2 
    {
    
    
        blFlag = true;						    // 为bool 类型变量赋值 
    }
    else
    {
    
    
        int sqr = (int)(sqrt((double)intNum));	// 对要判断的数字进行开方运算 

        for (int i = sqr; i >= 2; i--)			// 从开方后的数进行循环 
        {
    
    
            if (intNum % i == 0)				// 对要判断的数字和指定数字进行求余运算 
            {
    
    
                blFlag = false;				    // 如果余数为 0,说明不是素数 
            }
        }
    }

    return blFlag;							    // 返回bool 型变量 
}

V. Summary

The C language classic algorithm example in this article: find the maximum and minimum values ​​of a two-dimensional array, the goal to be achieved is as follows

  1. Any sufficiently large even number can be expressed as the sum of two prime numbers, or the sum of a prime number and a semi-prime number.
  2. The even number input is an even number greater than 6.
  3. Verify Goldbach's conjecture for numbers between 1 and 100.
  4. The program adopts the idea of ​​function modularization.

insert image description here

The article ends here.
I hope that the C language classic algorithm example in this article: verify Goldbach's conjecture.
It can inspire your love for C language and algorithm learning.

  • Your support is my greatest encouragement.

Guess you like

Origin blog.csdn.net/m0_47419053/article/details/126794077
Recommended