Pascal Program: 10 Ways to divide Two Numbers
Pascal Program: 10 Ways to Divide Two Numbers
In this tutorial, we will discuss “Pascal Program: 10 Ways to Divide Two Numbers.”
You want to see different ways of dividing two numbers in Pascal. Let’s go step by step with different approaches.
In this article, we use 10 different ways to divide two numbers.

Real division using “/” operator
In this program, we are using the normal division (/) operator with a variable
Program 1
//Real Division using "/" operator
program DivideTwoNum;
var num1,num2:Integer;
result:real;
begin
writeln ('Divide two numbers using "/" operator');
num1:=50;
num2:=10;
result:=num1/num2;
writeln ('Result = ',result:0:2);
end.
When the above code is executed, it produces the following result
Divide two numbers using "/" operator Result = 5.00
Integer Division using Div
In this program, we are using the ‘div’ operator to find quotient
Program 2
//Divide two numbers using "div" operator
program DivideTwoNum;
var num1,num2,quotient:Integer;
begin
writeln ('Divide two numbers using "div" operator');
num1:=50;
num2:=18;
quotient:=num1 div num2;
writeln ('Quotient = ',quotient);
end.
When the above code is executed, it produces the following result
Divide two numbers using "div" operator Quotient = 2
Divide two numbers using “mod” operator
In this program, we are using the ‘mod’ operator to find remainder
Program 3
//Divide two numbers using "mod" operator
program DivideTwoNumUsingMod;
var num1,num2,remainder:Integer;
begin
writeln ('Divide two numbers using "mod" operator');
num1:=50;
num2:=18;
remainder:=num1 mod num2;
writeln ('Remainder = ',remainder);
end.
When the above code is executed, it produces the following result
Divide two numbers using "mod" operator Remainder = 14
Find quotient and remainder using div and mod
In this program, we are using the ‘div and mod’ operator to find quotient and remainder
Program 4
//Find quotient and remainder using div and mod
program DivideTwoNumDivMod;
var num_1,num_2,quotient,remainder:Integer;
begin
writeln ('Find quotient and remainder using "div" and mod" operator');
num_1:=60;
num_2:=13;
quotient:=num_1 div num_2;
remainder:=num_1 mod num_2;
writeln('quotient =', quotient);
writeln('Remainder =', remainder);
end.
When the above code is executed, it produces the following result
Find quotient and remainder using "div" and mod" operator quotient =4 Remainder =8
Using user input
In this program, we are input the value to variable
Program 5
//Divide two numbers using user input operator
program DivideTwoNumUsingInput;
var num1,num2:real;
begin
writeln ('Divide two numbers using user input operator');
writeln ('Enter two numbers');
readln(num1,num2);
if num2<>0 then
writeln('Result =',num1/num2:0:2)
else
writeln ('Division by zero not allowed');
end.
When the above code is executed, it produces the following result
Divide two numbers using user input Enter two numbers 45 15 Result =3.00
Using function
In this program, we are using function to divide two numbers
Program 5
//Divide two numbers using function
program DivideUsingFunction;
function divide(a,b:real):real;
begin
divide:=a/b;
end;
begin
writeln ('Result= ',divide(28,4):0:2);
end.
When the above code is executed, it produces the following result
Result= 7.00
Using procedure
In this program, we are using procedure to divide two numbers
Program 6
//Divide two numbers using procedure
program DivideUsingProcedure;
procedure divide(a,b:real);
begin
if b<>0 then
writeln ('Result= ',a/b:0:2)
else
writeln ('Cannot divide by zero ');
end;
begin
divide(30,5);
end.
When the above code is executed, it produces the following result
Result= 6.00
Using Repeaed Subtraction
In this program, we are using while loop to divide two numbers
Program 7
//Divide two numbers using Repeated Subtraction
program DivideUsingRepeatedSubtraction;
var a,b,q,r:integer;
begin
a:=22; b:=5; q:=0;
while a>= b do
begin
a:=a-b;
q:=q+1;
end;
r:=a;
writeln ('Quotient= ',q,',Remainder=',r);
end.
When the above code is executed, it produces the following result
Quotient= 4,Remainder=2
Using with for loop
In this program, we are using for loop to divide two numbers
Program 8
//Divide two numbers using Forloop
program DivideUsingForLoop;
var a,b,q,temp:integer;
begin
a:=45; b:=5; temp:=0;
for q:=0 to a do
begin
temp:=temp+b;
if temp > a then break;
end;
writeln ('Quotient= ',q);
end.
When the above code is executed, it produces the following result
Quotient= 9
Using Division with conditional check
Program 9
//Divide two numbers using Conditional Check
program DivideWithConditionalCheck;
var a,b,q:real;
begin
a:=40; b:=8;
if b =0 then
writeln ('Division by Zero')
else
writeln ('Result= ',a/b:0:2);
end.
When the above code is executed, it produces the following result
Result= 5.00
Using Division with Recursion (Repeated Subtraction)
In this program, we are using recursive function to divide two numbers
Program 10
//Divide two numbers using Conditional Check
program DivideWithRecursion;
function divideRec(a,b:integer):integer;
begin
if a<b then divideRec:=0
else divideRec:=1 + divideRec(a-b,b);
end;
begin
writeln ('Quotient= ',divideRec(25,5));
end.
When the above code is executed, it produces the following result
Quotient= 5
Similar post
Find product of two numbers using method in Java
Find product of two numbers using recursion in Java
Multiply two numbers in C language
Multiply two numbers in C++ language
Multiply two numbers in Python language
C Program to Divide of two integer numbers
Java Program to Divide of two integer numbers
C++ Program to Divide of two integer numbers
Python Program to Divide of two integer numbers
How to divide two numbers in Java – 5 ways
Java code to Add two numbers – 5 ways