1) It is given that x mod y returns the remainder of x divided by y. For example,
5 mod 3 = 2, 17 mod 10 = 7, 6 mod 2 = 0, 2 mod 11 = 2. State the outputs of the following program.
program q3;
var i,x:integer;
begin
x:=38;
writeln('i':5,'x':5);
for i:=11 to 14 do
begin
x:=x mod i;
x:=x*x;
writeln(i:5 ,x:5);
end;
readln;
end.
我已經用pascal run 過個program 架啦,揾到個答案係︰
i=11 x=25
i=12 x=1
i=13 x=1
i=14 x=1
但係我exam 既時候係做paper 架,唔可以用pascal run ,可唔可以解釋吓究竟個program 係揾D咩野架?仲有我要點揾D outputs 呀?
點解當i=12,13,14 個陣,x 會係1既?
仲有i:5 & x:5 係點解呀?同x:0:1 有咩分別呀?
2)
program q1;
var x, y, z : real;
begin
readln(x,y,z);
if (x > y) and (x < z) then x := x + (z - y)/2;
if (x > z) and (x < y) then x := x + (y - z)/2;
if (x = y) and (x < z) then begin x := z/2 ; y := z/2; z := 0 end;
if (x = z) and (x < y) then begin x := y/2 ; z := y/2; y := 0 end;
if (x = y) and (x = z) then begin x := y + z; y := x - z end;
writeln(x :4:1, y :4:1, z :4:1);
readln;
end.
State the output values of x, y and z if x, y and z are inputted as follows:
input output
a) x = 1, y = 2, z = 6 x = _ 1.0__, y = __2.0__, z = _6.0_
b) x = 3, y = 2, z = 1 x = __3.0__, y = __2.0__, z = __1.0_
c) x = 2, y = 5, z = 2 x = __2.5__, y = __0.0 , z = __2.5_
d) x = 3, y = 3, z = 3 x = __6.0__, y = __3.0__, z = __3.0_
我想問吓係唔係當input 個D 數,唔符合program 寫既任何一個情況,output 就照寫番input 個堆數呀?仲有x:4:1 即係咩意思呀?
Exam 就到啦! 請各位好心人教教我! 萬分感激!