PL/SQL Program to Check Number is Odd or Even

PL/SQL Program to Check Number is Odd or Even

In this article, You will be able to understand how to write a PL/SQL Program to Check Number is Odd or Even.

An even number may be a number that will be divided into two equal groups. An odd number must be a number that can’t be divided into two equal groups.

Even numbers end in 2, 4, 6, 8, and 0 no matter what percentage digits they need (we know the amount 3,817,624 is even because it ends during a 4!). Odd numbers end with 1, 3, 5, 7, 9,11,13.

This is one of the commonly asked interview questions which is frequently asked as Write a PL/SQL program for a given number is even or odd during your interviews.

PL/SQL Program to Check Number is Odd or Even

n number:=&n;
if mod(n,2)=0
dbms_output.put_line('The given number is even');
dbms_output.put_line('The given number is odd');
end if;

The below ER diagram helps us to understand the process flow. How to print odd or even numbers using the PLSQL program.

The first user must specify the number which we are going to print at the end. As a next step, we need to check whether it is divisible by two or not.

It gives the output either zero or a value.

If the returned value is zero obviously it is an even number. Why because we know all even numbers divisible by zero.

In case the program returned value is not a zero we can consider it is not divisible by zero hence it is an odd number.

Hope you are clear with this part.

plsql program check number odd even


Enter a value for n: 8
old 2: n number:=&n;
new 2: n number:=8;
number is even


When you give the input value as 8 to the PLSQL program it takes the input and validates it with our program.

We have defined a step where it has to check the mod of a given number


You May Also Like:

Leave a comment