0% found this document useful (0 votes)
4 views1 page

Perfect Number

The document is a Pascal unit named 'Question2_U' that defines a form with a spin edit, label, and button. When the button is clicked, it checks if the number inputted is a perfect number by summing its divisors and comparing it to the original number. A message is displayed indicating whether the number is perfect or not.

Uploaded by

bestburrito824
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Perfect Number

The document is a Pascal unit named 'Question2_U' that defines a form with a spin edit, label, and button. When the button is clicked, it checks if the number inputted is a perfect number by summing its divisors and comparing it to the original number. A message is displayed indicating whether the number is perfect or not.

Uploaded by

bestburrito824
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Question2_U.

pas 5/16/2024 2:35:24 PM Page 1 of 1

1: // NAME
2: unit Question2_U;
3:
4: interface
5:
6: uses
7: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
8: Dialogs, StdCtrls, Spin;
9:
10: type
11: TForm1 = class(TForm)
12: spedtKM: TSpinEdit;
13: Label1: TLabel;
14: Button1: TButton;
15: procedure Button1Click(Sender: TObject);
16: private
17: { Private declarations }
18: public
19: { Public declarations }
20: end;
21:
22: var
23: Form1: TForm1;
24:
25: implementation
26:
27: {$R *.dfm}
28:
29: procedure TForm1.Button1Click(Sender: TObject);
30: var
31: iNum, I, iSum: integer;
32: begin
33: // Question 2
34: iNum := spedtKM.Value;
35: iSum := 0;
36:
37: if (iNum > 0) then
38: begin
39: for I := 1 to iNum do
40: if (iNum MOD I = 0) then
41: iSum := iSum + I;
42: end;
43:
44: if (iNum = iSum - iNum) then
45: ShowMessage('Perfect Number')
46: else
47: ShowMessage('Not a perfect Number');
48:
49: end;
50:
51: end.

You might also like