# Check if large number is divisible by 6

Here given code implementation process.

``````/*
C program for
Check if large number is divisible by 6
*/
#include <stdio.h>
#include <string.h>

void divisibleBy6(const char *num)
{
// Get the length of num
int n = strlen(num);
if (n == 0)
{
return;
}
if (((num[n - 1] - '0') % 2) != 0)
{
// When number is not divisible by 2
printf("\n Number %s is not divisible by 6", num);
}
else
{
int sum = 0;
// Execute loop through by size n
for (int i = 0; i < n; ++i)
{
// Sum of digits in given num
sum = sum + (num[i] - '0');
}
if ((sum) % 3 == 0)
{
// When sum is not divisible by 3
printf("\n Number %s divisible by 6", num);
}
else
{
printf("\n Number %s is not divisible by 6", num);
}
}
}
int main(int argc, char const *argv[])
{
// Test Inputs
divisibleBy6("160");
divisibleBy6("93782639377588932984");
divisibleBy6("33612315332343");
divisibleBy6("3824566134312");
return 0;
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````/*
Java program for
Check if large number is divisible by 6
*/
class Divisibility
{
public void divisibleBy6(String num)
{
// Get the length of num
int n = num.length();
if (n == 0)
{
return;
}
if (((num.charAt(n - 1) - '0') % 2) != 0)
{
// When number is not divisible by 2
System.out.print("\n Number " + num + " is not divisible by 6");
}
else
{
int sum = 0;
// Execute loop through by size n
for (int i = 0; i < n; ++i)
{
// Sum of digits in given num
sum = sum + (num.charAt(i) - '0');
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
System.out.print("\n Number " + num + " divisible by 6");
}
else
{
System.out.print("\n Number " + num + " is not divisible by 6");
}
}
}
public static void main(String[] args)
{
// Test Inputs
}
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
C++ program for
Check if large number is divisible by 6
*/
class Divisibility
{
public: void divisibleBy6(string num)
{
// Get the length of num
int n = num.length();
if (n == 0)
{
return;
}
if (((num[n - 1] - '0') % 2) != 0)
{
// When number is not divisible by 2
cout << "\n Number " << num << " is not divisible by 6";
}
else
{
int sum = 0;
// Execute loop through by size n
for (int i = 0; i < n; ++i)
{
// Sum of digits in given num
sum = sum + (num[i] - '0');
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
cout << "\n Number " << num << " divisible by 6";
}
else
{
cout << "\n Number " << num << " is not divisible by 6";
}
}
}
};
int main()
{
// Test Inputs
return 0;
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````// Include namespace system
using System;
/*
Csharp program for
Check if large number is divisible by 6
*/
public class Divisibility
{
public void divisibleBy6(String num)
{
// Get the length of num
int n = num.Length;
if (n == 0)
{
return;
}
if (((num[n - 1] - '0') % 2) != 0)
{
// When number is not divisible by 2
Console.Write("\n Number " + num + " is not divisible by 6");
}
else
{
int sum = 0;
// Execute loop through by size n
for (int i = 0; i < n; ++i)
{
// Sum of digits in given num
sum = sum + (num[i] - '0');
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
Console.Write("\n Number " + num + " divisible by 6");
}
else
{
Console.Write("\n Number " + num + " is not divisible by 6");
}
}
}
public static void Main(String[] args)
{
// Test Inputs
}
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````package main
import "fmt"
/*
Go program for
Check if large number is divisible by 6
*/

func divisibleBy6(num string) {
// Get the length of num
var n int = len(num)
if n == 0 {
return
}
if ((num[n - 1] - '0') % 2) != 0 {
// When number is not divisible by 2
fmt.Print("\n Number ", num, " is not divisible by 6")
} else {
var sum int = 0
// Execute loop through by size n
for i := 0 ; i < n ; i++ {
// Sum of digits in given num
sum = sum + int(num[i] - '0')
}
if (sum % 3) == 0 {
// When sum is not divisible by 3
fmt.Print("\n Number ", num, " divisible by 6")
} else {
fmt.Print("\n Number ", num, " is not divisible by 6")
}
}
}
func main() {

// Test Inputs
divisibleBy6("160")
divisibleBy6("93782639377588932984")
divisibleBy6("33612315332343")
divisibleBy6("3824566134312")
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````<?php
/*
Php program for
Check if large number is divisible by 6
*/
class Divisibility
{
public	function divisibleBy6(\$num)
{
// Get the length of num
\$n = strlen(\$num);
if (\$n == 0)
{
return;
}
if (((ord(\$num[\$n - 1]) - ord('0')) % 2) != 0)
{
// When number is not divisible by 2
echo("\n Number ".\$num.
" is not divisible by 6");
}
else
{
\$sum = 0;
// Execute loop through by size n
for (\$i = 0; \$i < \$n; ++\$i)
{
// Sum of digits in given num
\$sum = \$sum + (ord(\$num[\$i]) - ord('0'));
}
if ((\$sum % 3) == 0)
{
// When sum is not divisible by 3
echo("\n Number ".\$num.
" divisible by 6");
}
else
{
echo("\n Number ".\$num.
" is not divisible by 6");
}
}
}
}

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

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````/*
Node JS program for
Check if large number is divisible by 6
*/
class Divisibility
{
divisibleBy6(num)
{
// Get the length of num
var n = num.length;
if (n == 0)
{
return;
}
if (((num.charCodeAt(n - 1) - '0'.charCodeAt(0)) % 2) != 0)
{
// When number is not divisible by 2
process.stdout.write("\n Number " + num + " is not divisible by 6");
}
else
{
var sum = 0;
// Execute loop through by size n
for (var i = 0; i < n; ++i)
{
// Sum of digits in given num
sum = sum + (num.charCodeAt(i) - '0'.charCodeAt(0));
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
process.stdout.write("\n Number " + num + " divisible by 6");
}
else
{
process.stdout.write("\n Number " + num + " is not divisible by 6");
}
}
}
}

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

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````#    Python 3 program for
#    Check if large number is divisible by 6
class Divisibility :
def divisibleBy6(self, num) :
#  Get the length of num
n = len(num)
if (n == 0) :
return

if (((ord(num[n - 1]) - ord('0')) % 2) != 0) :
#  When number is not divisible by 2
print("\n Number ", num ," is not divisible by 6", end = "")
else :
sum = 0
i = 0
#  Execute loop through by size n
while (i < n) :
#  Sum of digits in given num
sum = sum + (ord(num[i]) - ord('0'))
i += 1

if ((sum % 3) == 0) :
#  When sum is not divisible by 3
print("\n Number", num ,"divisible by 6", end = "")
else :
print("\n Number", num ,"is not divisible by 6", end = "")

def main() :
#  Test Inputs

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

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number  33612315332343  is not divisible by 6
Number 3824566134312 divisible by 6``````
``````#    Ruby program for
#    Check if large number is divisible by 6
class Divisibility
def divisibleBy6(num)
#  Get the length of num
n = num.length
if (n == 0)
return
end

if (((num[n - 1].ord - '0'.ord) % 2) != 0)
#  When number is not divisible by 2
print("\n Number ", num ," is not divisible by 6")
else

sum = 0
i = 0
#  Execute loop through by size n
while (i < n)
#  Sum of digits in given num
sum = sum + (num[i].ord - '0'.ord)
i += 1
end

if ((sum % 3) == 0)
#  When sum is not divisible by 3
print("\n Number ", num ," divisible by 6")
else

print("\n Number ", num ," is not divisible by 6")
end

end

end

end

def main()
#  Test Inputs
end

main()``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````import scala.collection.mutable._;
/*
Scala program for
Check if large number is divisible by 6
*/
class Divisibility()
{
def divisibleBy6(num: String): Unit = {
// Get the length of num
var n: Int = num.length();
if (n == 0)
{
return;
}
if (((num.charAt(n - 1).toInt - '0'.toInt) % 2) != 0)
{
// When number is not divisible by 2
print("\n Number " + num + " is not divisible by 6");
}
else
{
var sum: Int = 0;
var i: Int = 0;
// Execute loop through by size n
while (i < n)
{
// Sum of digits in given num
sum = sum + (num.charAt(i).toInt - '0'.toInt);
i += 1;
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
print("\n Number " + num + " divisible by 6");
}
else
{
print("\n Number " + num + " is not divisible by 6");
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Divisibility = new Divisibility();
// Test Inputs
}
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````import Foundation;
/*
Swift 4 program for
Check if large number is divisible by 6
*/
class Divisibility
{
func divisibleBy6(_ data: String)
{
let num = Array(data);
// Get the length of num
let n: Int = num.count;
if (n == 0)
{
return;
}
if (((Int(UnicodeScalar(String(num[n - 1]))!.value) -
Int(UnicodeScalar(String("0"))!.value)) % 2)  != 0)
{
// When number is not divisible by 2
print("\n Number", data ,"is not divisible by 6", terminator: "");
}
else
{
var sum: Int = 0;
var i: Int = 0;
// Execute loop through by size n
while (i < n)
{
// Sum of digits in given num
sum = sum + (Int(UnicodeScalar(String(num[i]))!.value) -
Int(UnicodeScalar(String("0"))!.value));
i += 1;
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
print("\n Number", data ,"divisible by 6",
terminator: "");
}
else
{
print("\n Number", data ,"is not divisible by 6",
terminator: "");
}
}
}
}
func main()
{
// Test Inputs
}
main();``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````
``````/*
Kotlin program for
Check if large number is divisible by 6
*/
class Divisibility
{
fun divisibleBy6(num: String): Unit
{
// Get the length of num
val n: Int = num.length;
if (n == 0)
{
return;
}
if (((num.get(n - 1).toInt() - '0'.toInt()) % 2) != 0)
{
// When number is not divisible by 2
print("\n Number " + num + " is not divisible by 6");
}
else
{
var sum: Int = 0;
var i: Int = 0;
// Execute loop through by size n
while (i < n)
{
// Sum of digits in given num
sum = sum + (num.get(i).toInt() - '0'.toInt());
i += 1;
}
if ((sum % 3) == 0)
{
// When sum is not divisible by 3
print("\n Number " + num + " divisible by 6");
}
else
{
print("\n Number " + num + " is not divisible by 6");
}
}
}
}
fun main(args: Array < String > ): Unit
{
// Test Inputs
}``````

#### Output

`````` Number 160 is not divisible by 6
Number 93782639377588932984 divisible by 6
Number 33612315332343 is not divisible by 6
Number 3824566134312 divisible by 6``````

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.

### New Comment 