Check if a large number is divisible by 6 or not | C ++ program to find if a number is divisible by 6 or not ; Function to find that number divisible by 6 or not ; Return false if number is not divisible by 2. ; Compute sum of digits ; Check if sum of digits is divisible by 3 ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string str ) { int n = str . length ( ) ; if ( ( str [ n - 1 ] - '0' ) % 2 != 0 ) return false ; int digitSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) digitSum += ( str [ i ] - '0' ) ; return ( digitSum % 3 == 0 ) ; } int main ( ) { string str = "1332" ; check ( str ) ? cout << " Yes " : cout << " No ▁ " ; return 0 ; }