
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Check if a number is multiple of 5 without using / and % operators in C++
Here we will see how to check a number is divisible by 5 or not. One simple approach is that if the number mod 5 = 0, then, the number is divisible by 5. But here we will not use / or % operator. To check whether a number is divisible by 5, we have to see the last number is 0 or 5. If that is 0 or 5, the number is divisible by 5, otherwise not. Here we can use some large numbers also as a string to check.
Example
#include <bits/stdc++.h> using namespace std; bool isDiv5(string num){ int n = num.length(); if(num[n - 1] != '5' && num[n - 1] != '0') return false; return true; } int main() { string num = "154484585745184258458158245285265"; if(isDiv5(num)){ cout << "Divisible"; } else { cout << "Not Divisible"; } }
Output
Divisible
- Related Articles
- Check if n is divisible by power of 2 without using arithmetic operators in Python
- Multiply a number by 15 without using * and / operators in C++
- Check if a number is positive, negative or zero using bit operators in C++
- JavaScript: How to check if a number is even without using the modulo operator?
- Check if a number is perfect square without finding square root in C++
- Write an Efficient Method to Check if a Number is Multiple of 3 in C++
- Check if binary string multiple of 3 using DFA in Python
- Check if a large number is divisible by 5 or not in C++
- Check if a number in a list is perfect square using Python
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Check if table exist without using “select from” in MySQL?
- Check if a number is a power of another number in C++
- Check if a number is power of k using base changing methods in C++
- Multiples of 3 and 5 without using % operator in C++
- Check if a string contains a number using Java.

Advertisements