0% found this document useful (0 votes)
5 views

Pascal Examples

Uploaded by

jamdowndobson14
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)
5 views

Pascal Examples

Uploaded by

jamdowndobson14
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
You are on page 1/ 4

Subject: Information Technology

Grade: CSEC
Date: May 7, 2025
Topic: Pascal Examples:

Sequential Examples;
1. Write a pascal program to add two numbers

program AddNumbers;
var
num1, num2, sum: Integer;
begin
num1 := 5;
num2 := 7;
sum := num1 + num2;
writeln('Sum is: ', sum);
end.

2. Write a pascal program to find the area of a rectangle.


program RectangleArea;
var
length, width, area: Real;
begin
length := 10;
width := 5;
area := length * width;
writeln('Area of the rectangle is: ', area:0:2);
end.
3. Write a pascal program to calculate Celsius to Fahrenheit
program CelsiusToFahrenheit;
var
celsius, fahrenheit: Real;
begin
celsius := 25;
fahrenheit := (celsius * 9/5) + 32;
writeln('Temperature in Fahrenheit is: ', fahrenheit:0:2);
end.

4. Write a program to Calculate Simple Interest


program SimpleInterest;
var
principal, rate, time, interest: Real;
begin
principal := 1000;
rate := 5; // percent
time := 2; // years
interest := (principal * rate * time) / 100;
writeln('Simple Interest is: ', interest:0:2);
end.
Selection Examples: (IF...THEN / IF...THEN...ELSE)

1. A program that checks if a number is positive or negative.


program CheckNumber;
var
num: Integer;
begin
num := -3;
if num >= 0 then
writeln('The number is positive')
else
writeln('The number is negative');
end.

2. Find the Largest of Two Numbers

program MaxOfTwo;
var
a, b: Integer;
begin
a := 15;
b := 10;
if a > b then
writeln('The larger number is ', a)
else
writeln('The larger number is ', b);
end.
3. Write a program to grade a student score.
program GradeStudent;
var
score: Integer;
begin
score := 85;
if score >= 90 then
writeln('Grade: A')
else if score >= 80 then
writeln('Grade: B')
else if score >= 70 then
writeln('Grade: C')
else if score >= 60 then
writeln('Grade: D')
else
writeln('Grade: F');
end.

You might also like