
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
In this section we will see if one array is given with n numbers, we have to check if we make a number using all of the elements of these numbers, that number will be divisible by 3 or not. If the array elements are {15, 24, 23, 13}, then the we can make integer like 15242313. It will be divisible by 3.
Algorithm
checkDivThree(arr)
Begin rem := 0 for each element e in arr, do rem := (rem + e) mod 3 done if rem is 0, then return true end if return false End
Example
#include<iostream> #define MAX 4 using namespace std; bool checkDivThree(int arr[], int n){ int rem = 0; for(int i = 0; i<n; i++){ rem = (rem + arr[i]) % 3; } if(rem == 0){ return true; } return false; } main() { int arr[] = {15, 24, 23, 13}; int n = sizeof(arr)/sizeof(arr[0]); if(checkDivThree(arr, n)){ cout << "Divisible"; }else{ cout << "Not Divisible"; } }
Output
Divisible
- Related Articles
- 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
- Possible to make a divisible by 3 number using all digits in an array in C++
- Number of digits to be removed to make a number divisible by 3 in C++
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- C Program to Check if all digits of a number divide it
- Check whether it is possible to make both arrays equal by modifying a single element in Python
- C# Program to find whether the Number is Divisible by 2
- PHP program to check if all digits of a number divide it
- Java Program to check if all digits of a number divide it
- C++ program to check whether it is possible to finish all the tasks or not from given dependencies
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether sum of digits at odd places of a number is divisible by K in Python

Advertisements