0% found this document useful (0 votes)
4 views6 pages

Pascal Programs

The document contains several Pascal programs that perform basic mathematical operations. These include programs for adding, subtracting two numbers, calculating the area of a rectangle, sphere, and circle, as well as finding the volume of a sphere and solving a quadratic equation. Each program prompts the user for input and displays the result accordingly.

Uploaded by

Weissman Otieno
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Pascal Programs

The document contains several Pascal programs that perform basic mathematical operations. These include programs for adding, subtracting two numbers, calculating the area of a rectangle, sphere, and circle, as well as finding the volume of a sphere and solving a quadratic equation. Each program prompts the user for input and displays the result accordingly.

Uploaded by

Weissman Otieno
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Pascal programs

1 write a Pascal program which will enable the user to input 2 numbers add them and output the results

program AddTwoNumbers;

var

num1, num2, sum: Real;

begin

writeln('Enter the first number: ');

readln(num1);

writeln('Enter the second number: ');

readln(num2);

sum := num1 + num2;

writeln('The sum of ', num1:0:2, ' and ', num2:0:2, ' is ', sum:0:2);

readln;

end.

2 write a Pascal program which will enable the user to input 2 number subtract them and output the
results.

program SubtractTwoNumbers;

var

num1, num2, difference: Real;

begin

writeln('Enter the first number: ');


readln(num1);

writeln('Enter the second number: ');

readln(num2);

difference := num1 - num2;

writeln('The difference between ', num1:0:2, ' and ', num2:0:2, ' is ', difference:0:2);

readln;

end.

3 Write a pascal program which will enable the user enter length and width of rectangle and calculate
the area of rectangle.

program AreaOfRectangle;

var

length, width, area: Real;

begin

writeln('Enter the length of the rectangle: ');

readln(length);

writeln('Enter the width of the rectangle: ');

readln(width);

area := length * width;

writeln('The area of the rectangle is: ', area:0:2);


readln;

end.

4 Write a Pascal program to find area of a sphere.

S = 4\pi r^2

program AreaOfSphere;

const

PI = 3.142;

var

radius, area: Real;

begin

writeln('Enter the radius of the sphere: ');

readln(radius);

area := 4 * PI * radius * radius;

writeln('The surface area of the sphere is: ', area:0:2);

readln;

end.

5. Write a Pascal program to find volume of a sphere.

program VolumeOfSphere;

const

PI = 3.142;

var
radius, volume: Real;

begin

writeln('Enter the radius of the sphere: ');

readln(radius);

volume := (4.0 / 3.0) * PI * radius * radius * radius;

writeln('The volume of the sphere is: ', volume:0:2);

readln;

end.

6 write a pascal program to calculate the area of a circle

program AreaOfCircle;

const

PI = 3.142;

var

radius, area: Real;

begin

writeln('Enter the radius of the circle: ');

readln(radius);

area := PI * radius * radius;

writeln('The area of the circle is: ', area:0:2);


readln;

end.

7 write a pascal program to calculate the area of quadratic equation.

program QuadraticEquation;

uses Math;

var

a, b, c, d, x1, x2: Real;

begin

writeln('Enter the values of a, b and c: ');

readln(a, b, c);

d := (b * b) - (4 * a * c);

if d > 0 then

begin

x1 := (-b + sqrt(d)) / (2 * a);

x2 := (-b - sqrt(d)) / (2 * a);

writeln('Root 1 = ', x1:0:2);

writeln('Root 2 = ', x2:0:2);

end

else if d = 0 then

begin

x1 := -b / (2 * a);

writeln('Both roots are equal = ', x1:0:2);

end
else

writeln('The equation has no real roots.');

readln;

end.

You might also like