How to check for a prime number in Delphi

后端 未结 2 568
暖寄归人
暖寄归人 2021-01-17 06:57

I want to read all prime numbers between 1 and 10000 into a dynamic array and all non-prime numbers into another dynamic array and then read the prime array into riche

2条回答
  •  抹茶落季
    2021-01-17 07:15

    procedure TForm1.btnprimeClick(Sender: TObject); var K, I, iCount : Integer; begin for K := iStart to iEnd do begin iCount := 0; for I := 2 to iEnd do begin if K mod I = 0 then begin Inc(iCount); end; end; if iCount = 1 then begin memData.Lines.Add(IntToStr(K)); end; end; end;

提交回复
热议问题