Check if a larger number divisible by 36 | C ++ implementation to check divisibility by 36 ; Function to check whether a number is divisible by 36 or not ; null number cannot be divisible by 36 ; single digit number other than 0 is not divisible by 36 ; number formed by the last 2 digits ; if number is not divisible by 4 ; number is divisible by 4 calculate sum of digits ; sum of digits is not divisible by 9 ; number is divisible by 4 and 9 hence , number is divisible by 36 ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; string divisibleBy36 ( string num ) { int l = num . length ( ) ; if ( l == 0 ) return " No " ; if ( l == 1 && num [ 0 ] != '0' ) return " No " ; int two_digit_num = ( num [ l - 2 ] - '0' ) * 10 + ( num [ l - 1 ] - '0' ) ; if ( two_digit_num % 4 != 0 ) return " No " ; int sum = 0 ; for ( int i = 0 ; i < l ; i ++ ) sum += ( num [ i ] - '0' ) ; if ( sum % 9 != 0 ) return " No " ; return " Yes " ; } int main ( ) { string num = "92567812197966231384" ; cout << divisibleBy36 ( num ) ; return 0 ; }