- 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

# Possible to make a divisible by 3 number using all digits in an array in C++

In this problem, we are given an array. Our task is to check whether a number generated by using all digits of the elements of the array is divisible by 3. If possible then print *“Yes”* otherwise print *“No”*.

*Let’s take an example to understand the problem*

**Input** − arr = {3, 5, 91, }

**Output** − YES

**Explanation** − The number 5193 is divisible by 3. So, our answer is YES.

To solve this problem, we will check its divisibility by 3.

**Divisibility by 3** − a number is divisible by 3 if the sum of its digits is divisible by 3.

Now, we will have to find the sum of all array elements. If this sum is divisible by 3, then it is possible to print YES. otherwise No.

## Example

Program to show the implementation of our solution

#include <iostream> using namespace std; bool is3DivisibleArray(int arr[]) { int n = sizeof(arr) / sizeof(arr[0]); int rem = 0; for (int i=0; i<n; i++) rem = (rem + arr[i]) % 3; return (rem == 0); } int main(){ int arr[] = { 23, 64, 87, 12, 9 }; cout<<"Creating a number from digits of array which is divisible by 3 "; is3DivisibleArray(arr)?cout<<"is Possible":cout<<"is not Possible"; return 0; }

## Output

Creating a number from digits of array which is divisible by 3 is Possible

- Related Articles
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Number of digits to be removed to make a number divisible by 3 in C++
- Product of all the elements in an array divisible by a given number K in C++
- Possible cuts of a number such that maximum parts are divisible by 3 in C++
- Smallest possible number divisible by all numbers from 1 to n in JavaScript
- Minimum steps to make all the elements of the array divisible by 4 in C++
- Write all possible 3- digit numbers (without repeating the digits) , by using the digits.(i)6,7,5 (ii) 9,0,2
- Minimum number of operations on an array to make all elements 0 using C++.
- Find an array element such that all elements are divisible by it using c++
- Find N digits number which is divisible by D in C++
- Minimum number of given moves required to make N divisible by 25 using C++.
- Print digit’s position to be removed to make a number divisible by 6 in C++

Advertisements