Check if a large number is divisible by 75 or not | C ++ implementation to check the number is divisible by 75 or not ; check divisibleBy3 ; to store sum of Digit ; traversing through each digit ; summing up Digit ; check if sumOfDigit is divisibleBy3 ; check divisibleBy25 ; if a single digit number ; length of the number ; taking the last two digit ; checking if the lastTwo digit is divisibleBy25 ; Function to check divisibleBy75 or not ; check if divisibleBy3 and divisibleBy25 ; Drivers code ; divisible ; if divisibleBy75
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool divisibleBy3 ( string number ) { int sumOfDigit = 0 ; for ( int i = 0 ; i < number . length ( ) ; i ++ ) sumOfDigit += number [ i ] - '0' ; if ( sumOfDigit % 3 == 0 ) return true ; return false ; } bool divisibleBy25 ( string number ) { if ( number . length ( ) < 2 ) return false ; int length = number . length ( ) ; int lastTwo = ( number [ length - 2 ] - '0' ) * 10 + ( number [ length - 1 ] - '0' ) ; if ( lastTwo % 25 == 0 ) return true ; return false ; } bool divisibleBy75 ( string number ) { if ( divisibleBy3 ( number ) && divisibleBy25 ( number ) ) return true ; return false ; } int main ( ) { string number = "754586672150" ; bool divisible = divisibleBy75 ( number ) ; if ( divisible ) cout << " Yes " ; else cout << " No " ; return 0 ; }