- Related Questions & Answers
- C/C++ 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
- Python 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?
- Possible cuts of a number such that maximum parts are divisible by 3 in C++
- Product of all the elements in an array divisible by a given number K in C++
- C# program to print all the numbers divisible by 3 and 5 for a given number
- Minimum steps to make all the elements of the array divisible by 4 in C++
- Find N digits number which is divisible by D in C++
- Check if a large number is divisible by 3 or not in C++
- Program to print all the numbers divisible by 3 and 5 in C++
- Find an array element such that all elements are divisible by it using c++
- Minimum number of given moves required to make N divisible by 25 using C++.
- Python program to print all the numbers divisible by 3 and 5 for a given number
- Minimum number of operations on an array to make all elements 0 using C++.

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

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; }

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

Advertisements