Table of Contents
Overview
Below is the program to check whether a user input number is divisible by 5 or not.
REM Program to check if a number is divisible by 5 or not
CLS
INPUT "Enter a number: "; n
IF n MOD 5 = 0 THEN
PRINT n;" is divisible by 5"
ELSE
PRINT n;" is not divisible by 5"
END IF
END
Output
![Divisible by 5 QBASIC](https://thinkshare.one/wp-content/uploads/2021/08/Divisible-by-5-QBASIC.png)
Explanation
To check if a number is divisible by any number, we will be using the modulo operator (MOD). In this program, we need to check if the number is divisible by 5 or not, so we need to execute modulo division of the number by 5 i.e., n MOD 5. The modulo division returns a remainder 0 if the number is divisible and greater than 0 if the number is not divisible.
Hence, if the modulo division of number n by 5 returns 0 then display the number is divisible by 5 else not divisible by 5.
More Programs
https://thinkshare.one/learn/programming/qbasic/