
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Large Number is Divisible by 8 in C++
Here we will see how to check a number is divisible by 8 or not. In this case the number is very large number. So we put the number as string.
A number will be divisible by 8, if the number formed by last three digits are divisible by 8.
Example
#include <bits/stdc++.h> using namespace std; bool isDiv8(string num){ int n = num.length(); int last_three_digit_val = (num[n-3] - '0') * 100 + (num[n-2] - '0') * 10 + ((num[n-1] - '0')); if(last_three_digit_val % 8 == 0) return true; return false; } int main() { string num = "1754586672360"; if(isDiv8(num)){ cout << "Divisible"; }else{ cout << "Not Divisible"; } }
Output
Divisible
Advertisements