0% found this document useful (0 votes)
76 views7 pages

Prog WB2 Ans

The document provides examples of code segments that produce different outputs based on variable declarations and input values. It also provides mathematical expressions and functions to evaluate.

Uploaded by

api-3812419
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views7 pages

Prog WB2 Ans

The document provides examples of code segments that produce different outputs based on variable declarations and input values. It also provides mathematical expressions and functions to evaluate.

Uploaded by

api-3812419
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

5.

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

(b) readln (C1, C2, C3) ;


writeln (C1) ;
writeln (C2) ;
writeln (C3) ;

X Y Z
X
b
Y

(c) readln (C1, C2, C3, N1) ;


writeln (C1) ;
writeln (C2) ;
writeln (C3) ;
writeln (N1) ;

34.567 21
3
4
.
567

d)readln (S1, S2) ;


readln (S3) ;
writeln (S1) ;
writeln (S2) ;
writeln (S3) ;

This is string one This is string two


This is string three
This is string one This is string two

This is string three

e) readln (N1, C1, C2, N2) ;


writeln (N1) ;
writeln (N2) ;
writeln (C1) ;
writeln (C2) ;

567 1 2 234
567
2
1

f) readln (S1, C1) ;


readln (N1, N2) ;
readln (R1, R2) ;
writeln (S1) ;
writeln (C1) ;
writeln (N1) ;
writeln (N2) ;
writeln (R1) ;
writeln (R2) ;

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)

(e) Joey eats apple


Write(S, U:5,T:6)

(f) apple
Write(T:15)

(g) 2.35E +02


Write(R:9)

(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

Complete the program MarkList.


1 program MarkList ;
2 var
3 Name1, Name2, Name3 : ______string____ ;
4 Chinese1, Chinese2, Chinese3 : ____integer____;
5 English1,English2, English3: integer;
6 _Math1, Math2, Math3 :
integer;_____________________________________
7 begin
8 write (‘Enter name: ‘) ;
9.___readln(Name1);____________________________________________
___________
10 write (‘Enter Chinese, English, Mathematics marks:’);
11 readln(Chinese1, English1, Math1);
12 _write(‘Enter name:’);
13 _readln(Name2);
14 write(‘Enter Chinese , English, Mathematics,marks:’);
15 readln(Chinese2, English2, Math2);
16 _write(‘Enter name:’);
17 _readln(Name3);
18 _write(‘Enter Chinese, English, Mathematics marks:’);
19 readln(Chinese3, English3, Math3);
20 writeln (‘Name’ :12__________________________________ ,
‘Chinese’ _:12_______________________________ ,
‘English’ ____:12____________________________ ,
‘Mathematics’ ____:12__________________________) ;

21 writeln (Name1 __:12__________________________________ ,


Chinese1 __:12________________________________ ,
English :12 , Math :12 );
22 writeln(Name2:12, Chinese2:12, English2:12, Math2:12);
23 writeln(Name3:12, Chinese3:12, Math3:12)
24 end.
13)Write down the result of the following expressions.
a) 12*-3+ -5
b) –5*6-18+7.0
c) 43/5
d) –22 div 6
e) –22 div –6
f) 22 mod 6
g) –22 mod –6
h) 43 div 5 mod 4
1a)-41 b)-4.1 000 000 000E+01
c)8.6 000 000 000E+00
d)-3 e)3 f)4
g)-4 h)0

14)Write down the result of the following functions.


i) abs(4.5)
j) abs(-999)
k) sqrt(9)
l) sqrt(-4)
m) trunc(9.9)
n) round(-99.9)
o) random(1)
p) sqrt(abs(-49))
q) 49.9 – trunc (49.9)
r) trunc (12345/1000) * 1000
s) 6* (2+3) / abs (-4+1) 1.0000000000E+01
t) 29 div 5 mod 3 2
u) 29 mod 5 div 3 1
2a)4. 5 000 000 000E+00 b)999 c)3.000 000 000 0E+00
d)Error e)9 f)-100

g)0 h

You might also like