- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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 11 or not in C++

Here we will see how to check a number is divisible by 11 or not. In this case the number is very large number. So we put the number as string.

To check whether a number is divisible by 11, if the sum of odd position values and the sum of even position values are same, then the number is divisible by 11.

## Example

#include <bits/stdc++.h> using namespace std; bool isDiv11(string num){ int n = num.length(); long odd_sum = 0, even_sum = 0; for(int i = 0; i < n; i++){ if(i % 2 == 0){ odd_sum += num[i] - '0'; } else { even_sum += num[i] - '0'; } } if(odd_sum == even_sum) return true; return false; } int main() { string num = "1234567589333892"; if(isDiv11(num)){ cout << "Divisible"; } else { cout << "Not Divisible"; } }

## Output

Divisible

- Related Questions & Answers
- 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 13 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 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 a large number is divisible by 2, 3 and 5 or not in C++
- Check if a number is divisible by 23 or not in C++
- Check if a number is divisible by 41 or not in C++
- Check if a large number is divisible by 20 in C++

Advertisements