-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest7.w
More file actions
34 lines (32 loc) · 832 Bytes
/
test7.w
File metadata and controls
34 lines (32 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{COMS22201 test7: program to test all language features.}
{Already tested: write statements, constants, variables, assignment, read statements, if statements, while loops, arithmetic expressions, boolean expressions.}
write('Factorial calculator'); writeln;
write('Enter number: ');
read(x);
write('Factorial of '); write(x); write(' is ');
y := 1;
while !(x=1) do (
y := y * x;
x := x - 1
);
write(y);
writeln;
writeln;
write('Exponential calculator'); writeln;
write('Enter base: ');
read(base);
if 1 <= base then (
write('Enter exponent: ');
read(exponent);
num := 1;
count := exponent;
while 1 <= count do (
num := num * base;
count := count - 1
);
write(base); write(' raised to the power of '); write(exponent); write(' is ');
write(num)
) else (
write('Invalid base '); write(base)
);
writeln