- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a number is divisible by 23 or not in C++
Here we will see one program, that can check whether a number is divisible by 23 or not. Suppose a number 1191216 is given. This is divisible by 23.
To check the divisibility, we have to follow this rule −
Extract the last digit of the number/truncated number every time
add 7 * (last digit of the number calculated previous) to the truncated number
Repeat these steps as long as necessary.
17043, so 1704 + 7*3 = 1725 1725, so 172 + 7 * 5 = 207 207, this is 9 * 23, so 17043 is divisible by 23.
Example
#include <iostream> #include <algorithm> using namespace std; bool isDivisibleBy23(long long int n) { while (n / 100) { int last = n % 10; n /= 10; // Truncating the number n += last * 7; } return (n % 23 == 0); } int main() { long long number = 1191216; if(isDivisibleBy23(number)) cout << "Divisible"; else cout << "Not Divisible"; }
Output
Divisible
- Related Articles
- Check if a number is divisible by 41 or not in C++
- Check if a large number is divisible by 11 or not in C++
- Check if a large number is divisible by 25 or not in C++
- Check if a large number is divisible by 3 or not in C++
- Check if a large number is divisible by 5 or not in C++
- Check if a large number is divisible by 75 or not in C++
- Check if a large number is divisible by 8 or not in C++
- Check if a large number is divisible by 9 or not in C++
- Check if a large number is divisible by 13 or not in C++
- Check if a large number is divisible by 11 or not in java
- Check if a large number is divisible by 3 or not in java
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Check if any large number is divisible by 17 or not in Python
- Check if any large number is divisible by 19 or not in Python
- Check if LCM of array elements is divisible by a prime number or not in Python

Advertisements