Prog WB2 Ans
Prog WB2 Ans
With the given variables and their initial values, write a set of output statements that
will produce the following output.
Program OutputTest;
Var A: integer;
B: real;
C: char;
D: string;
Begin
A:=100;
B:= 999.0;
C:=’Z’;
D:=’Dummy’
end.
a) bb100bb999bbZbbDummy
write(A:5);
write(B:5:0);
write(C:3);
writeln(D:7);
b) 100bZb9.99E+02bDummy
write(A);
write(C:5:0);
write(B:9);
writeln(D:6);
c) DummyZ
999.000100
write(D);
writeln(C);
write(B:7:3);
writeln(A);
d) 1099.00ZZZZ
write(A +B :7:2);
writeln(C,C,C,C);
1. Refer to the following program declaration.
var
S1, S2, S3 : String;
C1, C2, C3 : char;
N1, N2 : integer;
R1, R2 : real;
Write down the output of each of the following program segments with the given
input values
(a) readln (N1, N2) ;
readln (N3) ;
writeln (N1) ;
writeln (N2) ;
writeln (N3) ;
12 23 34
98 87 76
12
23
98
X Y Z
X
b
Y
34.567 21
3
4
.
567
567 1 2 234
567
2
1
John Lee M
123 1 2 3 4 5
123.45 789
John Lee M
123
1
1.2345000000E+02
7.8900000000E+02
2. The following table shows the types and the values of the variables
M,N,R,C,D,E,S,T and U.
Variable Type Value
M integer 25
N integer 99
R real 234.5678
C char ‘X’
D char ‘+’
E char ‘=’
S string ‘Joey’
T string ‘apple’
U string ‘eats’
Use these variables to write output statements to produce the following output.
(Note: Any other strings and blanks are not allowed. The symbol ‘ ’ represents a
space.)
(a) 25
write(M)
(b) 9925
Write(N,M)
(c) 99 + 25 = 124
Write(N,D,M,E,M+N)
(d) 99 x 25
Write(N, C, N)
(f) apple
Write(T:15)
(h) 2.345678E + 02
Write(R:13)
(i) 235
Write(R:3:0)
(j) 234.57
Write(R:6:2)
(k) 2345.568
Write(R:10:3)
(l) 235234.57
Write(R:3:0, R:6:2)
3. A program MarkList reads the names of three students and their marks in the
Chinese, English and Mathematics tests and displays them in the format of a
table.
Sample output
Enter name: Amy
Enter Chinese, English and Mathematics marks : 88 56 65
Enter name : Billy
Enter Chinese, English and Mathematics marks : 100 82 90
Enter name : Carol
Enter Chinese, English and Mathematics marks : 45 37 50
Name Chinese English Mathematics
Amy 88 56 65
Billy 100 82 90
Carol 45 37 50
g)0 h