Check if a large number is divisibility by 15 | CPP program to check if a large number is divisible by 15 ; function to check if a large number is divisible by 15 ; length of string ; check divisibility by 5 ; Sum of digits ; if divisible by 3 ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisible ( string s ) { int n = s . length ( ) ; if ( s [ n - 1 ] != '5' and s [ n - 1 ] != '0' ) return false ; int sum = accumulate ( begin ( s ) , end ( s ) , 0 ) - '0' * n ; return ( sum % 3 == 0 ) ; } int main ( ) { string s = "15645746327462384723984023940239" ; isDivisible ( s ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; string s1 = "15645746327462384723984023940235" ; isDivisible ( s1 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; return 0 ; }