Вывести на экран все числа, на которые заданное число делится без остатка

Рейтинг: -1Ответов: 1Опубликовано: 03.05.2015

Нужно чтобы в мемо показывало все числа, на которые заданное число делится без остатка. У меня выдает ошибку

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var x, n: integer;
begin
 memo1.lines.beginupdate();
 n:= spinedit.value;
 try
 memo.clear();
 memo.lines.add(format('1 '#9'= %d / %d', [n, n]));

for x:= 2 div 2 downto 2 do
  if n mod x = 0
    then memo.lines.add(format('%d '#9'= %d / %d', [n div x, n, x]));
         if n > 1
         then memo.lines.add(format('1 '#9'= %d / %d', [n, n]));
    memo.lines.endupdate();
end;
end.

Ответы

▲ 1
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  x, n: integer;
begin
  Memo1.lines.beginupdate();
  n:=strtoint(edit1.text);
  try
    Memo1.clear();
    for x := n downto 1 do
      if n mod x = 0 then
        Memo1.lines.add(format('%d '#9'= %d / %d', [n div x, n, x]));
    Memo1.lines.endupdate();
  except
  end;
end;
end.