# Check that if large number is divisible by 24

Here given code implementation process.

``````// Java program for
// Check that if large number is divisible by 24
public class Divisibility
{
public void isDivisibleBy24(String num)
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
boolean result = false;
int n = num.length();
int auxiliary = 0;
if (n == 1 && num.charAt(0) == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num.charAt(i) - 48);
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num.charAt(n - 2) * 10 + num.charAt(n - 1);
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.charAt(n - 3) - 48) * 10 +
(num.charAt(n - 2) - 48)) * 10 +
(num.charAt(n - 1) - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
System.out.println(" Given number (" +
num + ") is divisible by 24");
}
else
{
System.out.println(" Given number (" +
num + ") is not divisible by 24");
}
}
public static void main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````// Include header file
#include <iostream>
#include <string>

using namespace std;
// C++ program for
// Check that if large number is divisible by 24
class Divisibility
{
public: void isDivisibleBy24(string num)
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
bool result = false;
int n = num.length();
int auxiliary = 0;
if (n == 1 && num[0] == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num[i] - 48);
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num[n - 2] *10 + num[n - 1];
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num[n - 3] - 48) *10 +
(num[n - 2] - 48)) *10 +
(num[n - 1] - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
cout << " Given number ("
<< num << ") is divisible by 24" << endl;
}
else
{
cout << " Given number ("
<< num << ") is not divisible by 24" << endl;
}
}
};
int main()
{
// Test
return 0;
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````// Include namespace system
using System;
// Csharp program for
// Check that if large number is divisible by 24
public class Divisibility
{
public void isDivisibleBy24(String num)
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
Boolean result = false;
int n = num.Length;
int auxiliary = 0;
if (n == 1 && num[0] == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
int sum = 0;
// Calculate sum of all digit
for (int i = 0; i < n; ++i)
{
sum += (num[i] - 48);
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num[n - 2] * 10 + num[n - 1];
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num[n - 3] - 48) * 10 +
(num[n - 2] - 48)) * 10 +
(num[n - 1] - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
Console.WriteLine(" Given number (" +
num + ") is divisible by 24");
}
else
{
Console.WriteLine(" Given number (" +
num + ") is not divisible by 24");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````package main
import "fmt"
// Go program for
// Check that if large number is divisible by 24

func isDivisibleBy24(num string) {
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
var result bool = false
var n int = len(num)
var auxiliary int = 0
if n == 1 && num[0] == '0' {
result = true
} else {
// Check number is divisible by 3 or not
var sum int = 0
// Calculate sum of all digit
for i := 0 ; i < n ; i++ {
sum += (int(num[i]) - 48)
}
if sum % 3 == 0 {
// When number divisible by 3
// Check number is divisible by 8 or not
if n == 2 {
auxiliary = int(num[n - 2]) * 10 + int(num[n - 1])
if auxiliary % 8 == 0 {
result = true
}
} else if n > 2 {
// Get last three digit number
auxiliary = ((int(num[n - 3]) - 48) * 10 +
(int(num[n - 2]) - 48)) * 10 +
(int(num[n - 1]) - 48)
if auxiliary % 8 == 0 {
result = true
}
}
}
}
if result {
fmt.Println(" Given number (", num, ") is divisible by 24")
} else {
fmt.Println(" Given number (", num, ") is not divisible by 24")
}
}
func main() {

// Test
isDivisibleBy24("45645624")
isDivisibleBy24("56456423434545645567567567867816")
isDivisibleBy24("5654464564564564512320")
isDivisibleBy24("56456423434545645567567567867824")
isDivisibleBy24("967345345365543456")
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````<?php
// Php program for
// Check that if large number is divisible by 24
class Divisibility
{
public	function isDivisibleBy24(\$num)
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
\$result = false;
\$n = strlen(\$num);
\$auxiliary = 0;
if (\$n == 1 && \$num[0] == '0')
{
\$result = true;
}
else
{
// Check number is divisible by 3 or not
\$sum = 0;
// Calculate sum of all digit
for (\$i = 0; \$i < \$n; ++\$i)
{
\$sum += (ord(\$num[\$i]) - 48);
}
if (\$sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (\$n == 2)
{
\$auxiliary = ord(\$num[\$n - 2]) * 10 + ord(\$num[\$n - 1]);
if (\$auxiliary % 8 == 0)
{
\$result = true;
}
}
else if (\$n > 2)
{
// Get last three digit number
\$auxiliary = ((ord(\$num[\$n - 3]) - 48) * 10 +
(ord(\$num[\$n - 2]) - 48)) * 10 +
(ord(\$num[\$n - 1]) - 48);
if (\$auxiliary % 8 == 0)
{
\$result = true;
}
}
}
}
if (\$result)
{
echo(" Given number (".\$num.
") is divisible by 24\n");
}
else
{
echo(" Given number (".\$num.
") is not divisible by 24\n");
}
}
}

function main()
{
// Test
}
main();``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````// Node JS program for
// Check that if large number is divisible by 24
class Divisibility
{
isDivisibleBy24(num)
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
var result = false;
var n = num.length;
var auxiliary = 0;
if (n == 1 && num.charAt(0) == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
var sum = 0;
// Calculate sum of all digit
for (var i = 0; i < n; ++i)
{
sum += (num.charCodeAt(i) - 48);
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num.charCodeAt(n - 2) * 10 +
num.charCodeAt(n - 1);
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.charCodeAt(n - 3) - 48) * 10 +
(num.charCodeAt(n - 2) - 48)) * 10 +
(num.charCodeAt(n - 1) - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
console.log(" Given number (" +
num + ") is divisible by 24");
}
else
{
console.log(" Given number (" +
num + ") is not divisible by 24");
}
}
}

function main()
{
// Test
}
main();``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````#  Python 3 program for
#  Check that if large number is divisible by 24
class Divisibility :
def isDivisibleBy24(self, num) :
#  Rule
#  ➀ number is divisible by 3 and
#  ➁ number is divisible by 8
result = False
n = len(num)
auxiliary = 0
if (n == 1 and num[0] == '0') :
result = True
else :
#  Check number is divisible by 3 or not
sum = 0
i = 0
#  Calculate sum of all digit
while (i < n) :
sum += (ord(num[i]) - 48)
i += 1

if (sum % 3 == 0) :
#  When number divisible by 3
#  Check number is divisible by 8 or not
if (n == 2) :
auxiliary = ord(num[n - 2]) * 10 + ord(num[n - 1])
if (auxiliary % 8 == 0) :
result = True

elif (n > 2) :
#  Get last three digit number
auxiliary = ((ord(num[n - 3]) - 48) * 10 +
(ord(num[n - 2]) - 48)) * 10 + (ord(num[n - 1]) - 48)
if (auxiliary % 8 == 0) :
result = True

if (result) :
print(" Given number (", num ,") is divisible by 24")
else :
print(" Given number (", num ,") is not divisible by 24")

def main() :
#  Test

if __name__ == "__main__": main()``````

#### Output

`````` Given number ( 45645624 ) is divisible by 24
Given number ( 56456423434545645567567567867816 ) is divisible by 24
Given number ( 5654464564564564512320 ) is not divisible by 24
Given number ( 56456423434545645567567567867824 ) is not divisible by 24
Given number ( 967345345365543456 ) is divisible by 24``````
``````#  Ruby program for
#  Check that if large number is divisible by 24
class Divisibility
def isDivisibleBy24(num)
#  Rule
#  ➀ number is divisible by 3 and
#  ➁ number is divisible by 8
result = false
n = num.length
auxiliary = 0
if (n == 1 && num[0] == '0')
result = true
else

#  Check number is divisible by 3 or not
sum = 0
i = 0
#  Calculate sum of all digit
while (i < n)
sum += (num[i].ord - 48)
i += 1
end

if (sum % 3 == 0)
#  When number divisible by 3
#  Check number is divisible by 8 or not
if (n == 2)
auxiliary = num[n - 2].ord * 10 + num[n - 1].ord
if (auxiliary % 8 == 0)
result = true
end

elsif (n > 2)
#  Get last three digit number
auxiliary = ((num[n - 3].ord - 48) * 10 +
(num[n - 2].ord - 48)) * 10 +
(num[n - 1].ord - 48)
if (auxiliary % 8 == 0)
result = true
end

end

end

end

if (result)
print(" Given number (", num ,") is divisible by 24\n")
else

print(" Given number (", num ,") is not divisible by 24\n")
end

end

end

def main()
#  Test
end

main()``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24
``````
``````// Scala program for
// Check that if large number is divisible by 24
class Divisibility()
{
def isDivisibleBy24(num: String): Unit = {
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
var result: Boolean = false;
var n: Int = num.length();
var auxiliary: Int = 0;
if (n == 1 && num.charAt(0) == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (num.charAt(i).toInt - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num.charAt(n - 2).toInt * 10 +
num.charAt(n - 1).toInt;
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.charAt(n - 3).toInt - 48) * 10 +
(num.charAt(n - 2).toInt - 48)) * 10 +
(num.charAt(n - 1).toInt - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
println(" Given number (" + num + ") is divisible by 24");
}
else
{
println(" Given number (" + num + ") is not divisible by 24");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Divisibility = new Divisibility();
// Test
}
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````
``````import Foundation;
// Swift 4 program for
// Check that if large number is divisible by 24
class Divisibility
{
func isDivisibleBy24(_ x: String)
{
let num = Array(x);
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
var result: Bool = false;
let n: Int = num.count;
var auxiliary: Int = 0;
if (n == 1 && num[0] == "0")
{
result = true;
}
else
{
// Check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (Int(UnicodeScalar(String(num[i]))!.value) - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = Int(UnicodeScalar(
String(num[n - 2]))!.value) * 10 +
Int(UnicodeScalar(
String(num[n - 1]))!.value);
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((Int(UnicodeScalar(
String(num[n - 3]))!.value) - 48) * 10 +
(Int(UnicodeScalar(
String(num[n - 2]))!.value) - 48)) * 10 +
(Int(UnicodeScalar(
String(num[n - 1]))!.value) - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
print(" Given number (", x ,") is divisible by 24");
}
else
{
print(" Given number (", x ,") is not divisible by 24");
}
}
}
func main()
{
// Test
}
main();``````

#### Output

`````` Given number ( 45645624 ) is divisible by 24
Given number ( 56456423434545645567567567867816 ) is divisible by 24
Given number ( 5654464564564564512320 ) is not divisible by 24
Given number ( 56456423434545645567567567867824 ) is not divisible by 24
Given number ( 967345345365543456 ) is divisible by 24``````
``````// Kotlin program for
// Check that if large number is divisible by 24
class Divisibility
{
fun isDivisibleBy24(num: String): Unit
{
// Rule
// ➀ number is divisible by 3 and
// ➁ number is divisible by 8
var result: Boolean = false;
val n: Int = num.length;
var auxiliary: Int;
if (n == 1 && num.get(0) == '0')
{
result = true;
}
else
{
// Check number is divisible by 3 or not
var sum: Int = 0;
var i: Int = 0;
// Calculate sum of all digit
while (i < n)
{
sum += (num.get(i).toInt() - 48);
i += 1;
}
if (sum % 3 == 0)
{
// When number divisible by 3
// Check number is divisible by 8 or not
if (n == 2)
{
auxiliary = num.get(n - 2).toInt() * 10 +
num.get(n - 1).toInt();
if (auxiliary % 8 == 0)
{
result = true;
}
}
else if (n > 2)
{
// Get last three digit number
auxiliary = ((num.get(n - 3).toInt() - 48) * 10 +
(num.get(n - 2).toInt() - 48)) * 10 +
(num.get(n - 1).toInt() - 48);
if (auxiliary % 8 == 0)
{
result = true;
}
}
}
}
if (result)
{
println(" Given number (" + num + ") is divisible by 24");
}
else
{
println(" Given number (" + num + ") is not divisible by 24");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

#### Output

`````` Given number (45645624) is divisible by 24
Given number (56456423434545645567567567867816) is divisible by 24
Given number (5654464564564564512320) is not divisible by 24
Given number (56456423434545645567567567867824) is not divisible by 24
Given number (967345345365543456) is divisible by 24``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.