CS Answer for classwork 3
Q1
program class3q1; uses wincrt;
var A, B, sum, difference, product, quotation : real;
begin
writeln('****************************');
writeln('* *');
writeln('* Pascal calculator *');
writeln('* Input two numbers and I *');
writeln('* will calculate on them *');
writeln('* *');
writeln('****************************');
writeln('First number : A = ?');
readln(A);
writeln('Second number : B = ?');
readln(B);
writeln;
writeln('Calculating.....');
writeln;
sum := A + B;
difference := A - B;
product := A * B;
quotation := A / B;
writeln(A:0:2,' + ',B:0:2,' = ',sum:0:2);
writeln(A:0:2,' - ',B:0:2,' = ',difference:0:2);
writeln(A:0:2,' * ',B:0:2,' = ',product:0:2);
writeln(A:0:2,' / ',B:0:2,' = ',quotation:0:2);
writeln;
writeln('Thankyou for using the program !')
end.
|
Q2
program class3q2; uses wincrt;
var a, b, c, d, e, f, x, y : real;
begin
writeln('This program is to solve two simultaneous equation with the following format.');
writeln('ax + by = c');
writeln('dx + ey = f');
writeln('Please enter the coefficients :');
write('a = ');
readln(a);
write('b = ');
readln(b);
write('c = ');
readln(c);
write('d = ');
readln(d);
write('e = ');
readln(e);
write('f = ');
readln(f);
writeln;
x := (b*f-e*c)/(b*d-a*e);
y := (a*f-c*d)/(a*e-b*d);
writeln('x = ',round(x),' and y = ',round(y))
end.
|
Q3
program class3q3; uses wincrt;
var n1, n2, n3, n4, n5 : integer;
mean, sd : real;
begin
randomize;
writeln('The following random numbers are generated :');
n1 := 1+random(25);
n2 := 1+random(25);
n3 := 1+random(25);
n4 := 1+random(25);
n5 := 1+random(25);
writeln(n1,', ',n2,', ',n3,', ',n4,', ',n5);
writeln('Statistics :');
mean := (n1+n2+n3+n4+n5)/5;
sd := sqrt((n1*n1+n2*n2+n3*n3+n4*n4+n5*n5)/5-mean*mean);
writeln('mean = ',mean:0:3);
writeln('s. d. = ',sd:0:3)
end.
|
¡@