0% found this document useful (0 votes)
40 views4 pages

Pascal Practical Programs

The document contains a series of Pascal programming examples that demonstrate basic programming concepts. Each program performs a specific task, such as adding two numbers, finding the square of a number, checking if a number is even or odd, and calculating the factorial of a number. These examples serve as practical exercises for learning Pascal programming.

Uploaded by

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

Pascal Practical Programs

The document contains a series of Pascal programming examples that demonstrate basic programming concepts. Each program performs a specific task, such as adding two numbers, finding the square of a number, checking if a number is even or odd, and calculating the factorial of a number. These examples serve as practical exercises for learning Pascal programming.

Uploaded by

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

Pascal Practical Programming Questions and

Answers

Program 1: Add Two Numbers


{ This program reads two numbers from the user and displays their sum. }
program AddNumbers;
uses crt;
var
num1, num2, sum: integer;
begin
clrscr;
write('Enter first number: ');
readln(num1);
write('Enter second number: ');
readln(num2);
sum := num1 + num2;
writeln('The sum is: ', sum);
readln;
end.

Program 2: Find the Square of a Number


{ This program calculates and displays the square of a number entered by the user. }
program SquareNumber;
uses crt;
var
num, square: integer;
begin
clrscr;
write('Enter a number: ');
readln(num);
square := num * num;
writeln('The square of ', num, ' is ', square);
readln;
end.

Program 3: Check if a Number is Even or Odd


{ This program checks whether a number entered by the user is even or odd. }
program EvenOdd;
uses crt;
var
num: integer;
begin
clrscr;
write('Enter a number: ');
readln(num);
if (num mod 2 = 0) then
writeln(num, ' is even.')
else
writeln(num, ' is odd.');
readln;
end.

Program 4: Find the Largest of Two Numbers


{ This program compares two numbers entered by the user and prints the largest one. }
program LargestNumber;
uses crt;
var
a, b: integer;
begin
clrscr;
write('Enter first number: ');
readln(a);
write('Enter second number: ');
readln(b);
if a > b then
writeln('The largest number is ', a)
else
writeln('The largest number is ', b);
readln;
end.

Program 5: Print the First 10 Natural Numbers


{ This program prints the first 10 natural numbers using a FOR loop. }
program NaturalNumbers;
uses crt;
var
i: integer;
begin
clrscr;
writeln('First 10 natural numbers:');
for i := 1 to 10 do
writeln(i);
readln;
end.

Program 6: Calculate Factorial of a Number


{ This program calculates the factorial of a given number using a FOR loop. }
program Factorial;
uses crt;
var
n, i, fact: integer;
begin
clrscr;
write('Enter a number: ');
readln(n);
fact := 1;
for i := 1 to n do
fact := fact * i;
writeln('Factorial of ', n, ' is ', fact);
readln;
end.

Program 7: Display Multiplication Table of a Number


{ This program prints the multiplication table of a number entered by the user. }
program MultiplicationTable;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Enter a number: ');
readln(n);
writeln('Multiplication table of ', n, ':');
for i := 1 to 10 do
writeln(n, ' x ', i, ' = ', n * i);
readln;
end.

Program 8: Find Sum of First N Natural Numbers


{ This program finds the sum of the first N natural numbers entered by the user. }
program SumNatural;
uses crt;
var
n, i, sum: integer;
begin
clrscr;
write('Enter value of n: ');
readln(n);
sum := 0;
for i := 1 to n do
sum := sum + i;
writeln('Sum of first ', n, ' natural numbers = ', sum);
readln;
end.

Program 9: Reverse a Number


{ This program reverses the digits of a number entered by the user. }
program ReverseNumber;
uses crt;
var
num, remainder, reversed: integer;
begin
clrscr;
write('Enter a number: ');
readln(num);
reversed := 0;
while num <> 0 do
begin
remainder := num mod 10;
reversed := (reversed * 10) + remainder;
num := num div 10;
end;
writeln('Reversed number = ', reversed);
readln;
end.

Program 10: Check if a Number is Prime


{ This program checks whether a number entered by the user is prime or not. }
program PrimeCheck;
uses crt;
var
n, i, count: integer;
begin
clrscr;
write('Enter a number: ');
readln(n);
count := 0;

for i := 1 to n do
begin
if (n mod i = 0) then
count := count + 1;
end;

if count = 2 then
writeln(n, ' is a prime number.')
else
writeln(n, ' is not a prime number.');
readln;
end.

You might also like