---
title: "哥德巴赫猜想的delphi7程序代码 "
author: "cfeers"
date: "2011-05-12T16:52:38Z"
tags: []
categories: ["编程语言"]
slug: "delphi7"
draft: false
lastmod: "2011-05-12T16:52:38Z"
id: 1041533
url: "https://cfeers.iteye.com/blog/1041533"
---

![](http://hiphotos.baidu.com/ysyhzlq/pic/item/661ca2273be5c74b918f9dea.jpg)

**unit Unit1;**

**interface**

**uses**  
**Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,**  
**Dialogs, StdCtrls;**

**type**  
**TForm1 = class(TForm)**  
    **lbl1: TLabel;**  
    **lbl2: TLabel;**  
    **btn1: TButton;**  
    **btn2: TButton;**  
    **edt1: TEdit;**  
    **edt2: TEdit;**  
    **lbl3: TLabel;**  
    **procedure btn1Click(Sender: TObject);**  
    **procedure btn2Click(Sender: TObject);**  
**private**  
    **{ Private declarations }**  
**public**  
    **{ Public declarations }**  
**end;**

**var**  
**Form1: TForm1;**

**implementation**

**{$R \*.dfm}**

**function numcheck(num:Integer):Boolean;**  
**var**  
**n:Integer;**  
**begin**  
**for n:=num-1 downto 2 do**  
**begin**  
    **if (num mod n)=0 then**  
       **Break**  
    **else**  
    **Result:=True;**  
**end;**  
**end;**

**procedure TForm1.btn1Click(Sender: TObject);**  
**var**  
**num,num1,num2,i,j:Integer;**  
**d1,d2:Boolean;**  
**begin**  
**try**  
     **StrToInt(edt1.Text);**  
   **except**  
      **showmessage('必需输入一个整数');**  
      **Exit;**  
**end;**  
**num:=StrToInt(edt1.text);**  
**if (((num mod 2)=0) and (num&gt;=6) )then**  
**begin**  
    **for num1:=2 to num do**  
    **begin**  
      **d1:=False;**  
      **d1:=numcheck(num1);**

      **if d1=True then**  
       **begin**  
         **num2:=num-num1;**  
         **d2:=False;**  
         **d2:=numcheck(num2);**  
         **if d2=True then**  
         **begin**  
            **edt2.Text:=IntToStr(num1)+'+'+inttostr(num2);**  
            **Break;**  
         **end;**

       **end;**

 

    **end;**  
    **btn2.SetFocus;**  
**end**  
**else**  
**begin**  
      **ShowMessage('输入的数字不合法');**  
      **edt1.Text:='';**  
      **edt1.SetFocus;**  
**end;**

   **end;**  
**procedure TForm1.btn2Click(Sender: TObject);**  
**begin**  
**edt1.Text:='';**  
**edt2.Text:='';**  
**edt1.SetFocus;**  
**end;**

**end.**