Dear ALL,

Could you tell me how can I get num1, num2 and Output 2 for the following programme.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils, ourcrt;

var
  num1, num2: integer;


begin
  num2:=0;
    repeat
      num1:=num2+1;
      if (num1 mod 2=1) then
        begin
          writeln(num2);
        end
        else
         begin
          num1:=num1+1;
         end;

         num2:=num2+1;
    until num2>4;
    readln;
end.

Recommended Answers

All 3 Replies

program project2;

{$APPTYPE CONSOLE}

uses
  SysUtils{, ourcrt};

var
  num1, num2: integer;

{let's see the first run}
begin
  num2:=0;
    repeat
      num1:=num2+1;   {num1=1}
      if (num1 mod 2=1) then {if there is remainder}
        begin
          writeln(num2);  {then write num2 that's 0}
        end
        else
         begin
          num1:=num1+1; {if there isn't,then num1=2}
         end;

         num2:=num2+1;  {num2=1}
    until num2>4;       {'till becomes true}
    readln;
end.
{
the results:
0
2
4

}

Sorry Turbomen,I didn't understand the question :'(
What do you want exactly?
To write the *num1*'s value...? :-O Or what?I wanna help,just give me more information about your imagination....

Sorry, I am late reply.

The above question is to ask me to create a table to show what happens to each variable during this code segment

Which means num1, num2 and Output num2 can have more than 1 answer.

program num1_num2;

{$APPTYPE CONSOLE}

uses
  SysUtils{, ourcrt};

var
  num1, num2: integer;


begin
  num2:=0;
    repeat
      num1:=num2+1;
      if (num1 mod 2=1) then
        begin
          writeln(num2);
        end
        else
         begin
          num1:=num1+1;
         end;

         num2:=num2+1;
    until num2>4;       {'till becomes true}
    readln;
end.
{
let's see the rounds one by one
'*' means output!
}
{
|1.Round!!!
|num2=0
|num1=num2+1=1
|if true that num1 mod 2=1
(num1 cannot divide by 2 without remainder)
|tests if there is remainder then out num2=0 *
|else increase num1 by 1 so num1=num1+1=2
|num2=num2+1=1
|end of the 1.round,
so num2>4 is False the repeat loop is continues
Output:0
*******************************************
2.Round!!!
|num2=1
|num1=num2+1=2
|if true that num1 mod 2=1
(tests if num1 cannot divide by 2 without remainder)
|if there is remainder then out num2=1
|else increase num1 by 1 so num1=num1+1=3
|num2=num2+1=2
|end of the 2.round,
so num2>4 is False the repeat loop is continues
output:nothing!
**********************************************
3.Round!!!
|num2=2
|num1=num2+1=3
|if true that num1 mod 2=1
(tests if num1 can divide by 2 without remainder)
|if there is remainder then out num2=2  *
|else increase num1 by 1 so num1=num1+1=4
|num2=num2+1=3
|end of the 3.round,
so num2>4 is False the repeat loop is continues
Output:2
**********************************************
4.Round!!!
|num2=3
|num1=num2+1=4
|if true that num1 mod 2=1
(tests if num1 can divide by 2 without remainder)
|if there is remainder then out num2=3
|else increase num1 by 1 so num1=num1+1=5
|num2=num2+1=4
|end of the 4.round,
so num2>4 is False the repeat loop is continues
Output:nothing!!
**********************************************
5.Round!!!
|num2=4
|num1=num2+1=5
|if true that num1 mod 2=1
(tests if num1 can divide by 2 without remainder)
|if there is remainder then out num2=4 *
|else increase num1 by 1 so num1=num1+1=6
|num2=num2+1=5
|end of the 3.round,
so num2>4 is True the stop the repeat loop
Output:4
}

I'm really happy that there weren't 100 rounds :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.