Gr11 For Loop Factors Etc
Gr11 For Loop Factors Etc
INFORMATION TECHNOLOGY
GRADE 10/11
Questions: N.B. design a project with one button and one richedit for each of
the following.
for i := 1 to inum do
begin
if inum mod i = 0 then
begin
redout.Lines.Add(inttostr(i));
end; //if
end; //loop
end;
2. Input an integer and determine if it is a prime number or not.
begin
//INPUT
inum:= strtoint(inputbox('Number','Enter a number','0'));
//DISPLAY THE NUMBER
redout.Lines.Add('Number: '+inttostr(inum));
redout.Lines.Add('Factors:');
for i := 1 to inum do
begin
if inum mod i = 0 then
begin
inc(ifactors); //count factors
redout.Lines.Add(inttostr(i)); //output factors
end; //if
end; //loop
end;
3. Input an integer and determine if the integer is a special number. A special number is
a number where the sum of its factors excluding itself is equal to itself.
e.g.s of special numbers include 6 and 28.
Integer: 6
1+2+3 = 6
// INITIALISE ISUM
isum:= 0;
end;
4. Allow the user to enter 2 integers for a range of numbers. Determine and list all
prime numbers that lie inbetween this range. Make sure you enter the smaller
number first and then the large.
for j := 1 to i do //inner loop - checking each number between range for factors
begin
if i mod j = 0 then
begin
inc(ifactors);
end; //if
end; //j loop
//checking if prime
if ifactors = 2 then
begin
reddisplay.Lines.Add(inttostr(i));
end; //if
end; //i loop
end;