Check if a large number is divisible by 2 , 3 and 5 or not | CPP program to Check if a large number is divisible by 2 , 3 and 5 or not . ; function to return sum of digits of a number ; function to Check if a large number is divisible by 2 , 3 and 5 or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int SumOfDigits ( string str , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( int ) ( str [ i ] - '0' ) ; return sum ; } bool Divisible ( string str , int n ) { if ( SumOfDigits ( str , n ) % 3 == 0 and str [ n - 1 ] == '0' ) return true ; return false ; } int main ( ) { string str = "263730746028908374890" ; int n = str . size ( ) ; if ( Divisible ( str , n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }