Skip to main content

Check if large number is divisible by 25

When we say "check if a large number is divisible by 25," it means we want to determine whether the given number can be evenly divided by 25 without leaving any remainder.

In other words, a number is divisible by 25 if it can be expressed as the product of 25 and another whole number. For example, 75 is divisible by 25 because 25 x 3 = 75, whereas 82 is not divisible by 25 because there is no whole number that can be multiplied by 25 to get 82 without a remainder.

To check if a large number is divisible by 25, you can use the following steps:

  1. Check if the last two digits of the number are either 00, 25, 50, or 75. If they are, then the number is divisible by 25.
  2. If the last two digits are not one of the above numbers, then the number is not divisible by 25.

For example, let's say we want to check if the number 3,725,000 is divisible by 25. We can look at the last two digits, which are "00", so the number is divisible by 25. On the other hand, if we want to check if the number 7,821 is divisible by 25, we can see that the last two digits are "21", which means the number is not divisible by 25.

Program Solution

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

void divisibleBy25(const char *num)
{
	// Get the length of number
	int n = strlen(num);
	if (n == 0)
	{
		return;
	}
	int result = 0;
	if (n == 1 && num[0] == '0')
	{
		result = 1;
	}
	else if (n > 1)
	{
		// Collect a number of last two digits
		int value = ((num[n - 2] - '0') *10) + (num[n - 1] - '0');
		if (value % 25 == 0)
		{
			result = 1;
		}
	}
	if (result == 1)
	{
		printf("\n Number %s is divisible by 25", num);
	}
	else
	{
		printf("\n Number %s is not divisible by 25", num);
	}
}
int main(int argc, char
	const *argv[])
{
	// Test Inputs
	divisibleBy25("115");
	divisibleBy25("937826393775889329125");
	divisibleBy25("33612315332343");
  	divisibleBy25("130");
	divisibleBy25("3824566134312124250");
	return 0;
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
/*
    Java program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	public void divisibleBy25(String num)
	{
		// Get the length of number
		int n = num.length();
		if (n == 0)
		{
			return;
		}
		boolean result = false;
		if (n == 1 && num.charAt(0) == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			int value = ((num.charAt(n - 2) - '0') * 10) + 
              			 (num.charAt(n - 1) - '0');
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			System.out.print("\n Number " + num + " is divisible by 25");
		}
		else
		{
			System.out.print("\n Number " + num + " is not divisible by 25");
		}
	}
	public static void main(String[] args)
	{
		Divisibility task = new Divisibility();
		// Test Inputs
		task.divisibleBy25("115");
		task.divisibleBy25("937826393775889329125");
		task.divisibleBy25("33612315332343");
		task.divisibleBy25("130");
		task.divisibleBy25("3824566134312124250");
	}
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
    C++ program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	public: void divisibleBy25(string num)
	{
		// Get the length of number
		int n = num.length();
		if (n == 0)
		{
			return;
		}
		bool result = false;
		if (n == 1 && num[0] == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			int value = ((num[n - 2] - '0') *10) + (num[n - 1] - '0');
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			cout << "\n Number " << num << " is divisible by 25";
		}
		else
		{
			cout << "\n Number " << num << " is not divisible by 25";
		}
	}
};
int main()
{
	Divisibility *task = new Divisibility();
	// Test Inputs
	task->divisibleBy25("115");
	task->divisibleBy25("937826393775889329125");
	task->divisibleBy25("33612315332343");
	task->divisibleBy25("130");
	task->divisibleBy25("3824566134312124250");
	return 0;
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
// Include namespace system
using System;
/*
    Csharp program for
    Check if large number is divisible by 25
*/
public class Divisibility
{
	public void divisibleBy25(String num)
	{
		// Get the length of number
		int n = num.Length;
		if (n == 0)
		{
			return;
		}
		Boolean result = false;
		if (n == 1 && num[0] == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			int value = ((num[n - 2] - '0') * 10) + (num[n - 1] - '0');
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			Console.Write("\n Number " + num + " is divisible by 25");
		}
		else
		{
			Console.Write("\n Number " + num + " is not divisible by 25");
		}
	}
	public static void Main(String[] args)
	{
		Divisibility task = new Divisibility();
		// Test Inputs
		task.divisibleBy25("115");
		task.divisibleBy25("937826393775889329125");
		task.divisibleBy25("33612315332343");
		task.divisibleBy25("130");
		task.divisibleBy25("3824566134312124250");
	}
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
package main
import "fmt"
/*
    Go program for
    Check if large number is divisible by 25
*/

func divisibleBy25(num string) {
	// Get the length of number
	var n int = len(num)
	if n == 0 {
		return
	}
	var result bool = false
	if n == 1 && num[0] == '0' {
		result = true
	} else if n > 1 {
		// Collect a number of last two digits
		var value int = (int(num[n - 2] - '0') * 10) + int(num[n - 1] - '0')
		if value % 25 == 0 {
			result = true
		}
	}
	if result == true {
		fmt.Print("\n Number ", num, " is divisible by 25")
	} else {
		fmt.Print("\n Number ", num, " is not divisible by 25")
	}
}
func main() {

	// Test Inputs
	divisibleBy25("115")
	divisibleBy25("937826393775889329125")
	divisibleBy25("33612315332343")
	divisibleBy25("130")
	divisibleBy25("3824566134312124250")
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
<?php
/*
    Php program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	public	function divisibleBy25($num)
	{
		// Get the length of number
		$n = strlen($num);
		if ($n == 0)
		{
			return;
		}
		$result = false;
		if ($n == 1 && $num[0] == '0')
		{
			$result = true;
		}
		else if ($n > 1)
		{
			// Collect a number of last two digits
			$value = ((ord($num[$n - 2]) - ord('0')) * 10) + (ord($num[$n - 1]) - ord('0'));
			if ($value % 25 == 0)
			{
				$result = true;
			}
		}
		if ($result == true)
		{
			echo("\n Number ".$num.
				" is divisible by 25");
		}
		else
		{
			echo("\n Number ".$num.
				" is not divisible by 25");
		}
	}
}

function main()
{
	$task = new Divisibility();
	// Test Inputs
	$task->divisibleBy25("115");
	$task->divisibleBy25("937826393775889329125");
	$task->divisibleBy25("33612315332343");
	$task->divisibleBy25("130");
	$task->divisibleBy25("3824566134312124250");
}
main();

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
/*
    Node JS program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	divisibleBy25(num)
	{
		// Get the length of number
		var n = num.length;
		if (n == 0)
		{
			return;
		}
		var result = false;
		if (n == 1 && num.charAt(0) == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			var value = ((num.charCodeAt(n - 2) - '0'.charCodeAt(0)) * 10) +
                (num.charCodeAt(n - 1) - '0'.charCodeAt(0));
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			process.stdout.write("\n Number " + num + " is divisible by 25");
		}
		else
		{
			process.stdout.write("\n Number " + num + " is not divisible by 25");
		}
	}
}

function main()
{
	var task = new Divisibility();
	// Test Inputs
	task.divisibleBy25("115");
	task.divisibleBy25("937826393775889329125");
	task.divisibleBy25("33612315332343");
	task.divisibleBy25("130");
	task.divisibleBy25("3824566134312124250");
}
main();

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
#    Python 3 program for
#    Check if large number is divisible by 25
class Divisibility :
	def divisibleBy25(self, num) :
		#  Get the length of number
		n = len(num)
		if (n == 0) :
			return
		
		result = False
		if (n == 1 and num[0] == '0') :
			result = True
		elif (n > 1) :
			#  Collect a number of last two digits
			value = ((ord(num[n - 2]) - ord('0')) * 10) + (
              ord(num[n - 1]) - ord('0')
            )
			if (value % 25 == 0) :
				result = True
			
		
		if (result == True) :
			print("\n Number ", num ," is divisible by 25", end = "")
		else :
			print("\n Number ", num ," is not divisible by 25", end = "")
		
	

def main() :
	task = Divisibility()
	#  Test Inputs
	task.divisibleBy25("115")
	task.divisibleBy25("937826393775889329125")
	task.divisibleBy25("33612315332343")
	task.divisibleBy25("130")
	task.divisibleBy25("3824566134312124250")

if __name__ == "__main__": main()

Output

 Number  115  is not divisible by 25
 Number  937826393775889329125  is divisible by 25
 Number  33612315332343  is not divisible by 25
 Number  130  is not divisible by 25
 Number  3824566134312124250  is divisible by 25
#    Ruby program for
#    Check if large number is divisible by 25
class Divisibility 
	def divisibleBy25(num) 
		#  Get the length of number
		n = num.length
		if (n == 0) 
			return
		end

		result = false
		if (n == 1 && num[0] == '0') 
			result = true
		elsif (n > 1) 
			#  Collect a number of last two digits
			value = ((num[n - 2].ord - '0'.ord) * 10) + 
              (num[n - 1].ord - '0'.ord)
			if (value % 25 == 0) 
				result = true
			end

		end

		if (result == true) 
			print("\n Number ", num ," is divisible by 25")
		else
 
			print("\n Number ", num ," is not divisible by 25")
		end

	end

end

def main() 
	task = Divisibility.new()
	#  Test Inputs
	task.divisibleBy25("115")
	task.divisibleBy25("937826393775889329125")
	task.divisibleBy25("33612315332343")
	task.divisibleBy25("130")
	task.divisibleBy25("3824566134312124250")
end

main()

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
/*
    Scala program for
    Check if large number is divisible by 25
*/
class Divisibility()
{
	def divisibleBy25(num: String): Unit = {
		// Get the length of number
		var n: Int = num.length();
		if (n == 0)
		{
			return;
		}
		var result: Boolean = false;
		if (n == 1 && num.charAt(0) == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			var value: Int = ((num.charAt(n - 2).toInt - '0'.toInt) * 10) + 
              (num.charAt(n - 1).toInt - '0'.toInt);
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			print("\n Number " + num + " is divisible by 25");
		}
		else
		{
			print("\n Number " + num + " is not divisible by 25");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Divisibility = new Divisibility();
		// Test Inputs
		task.divisibleBy25("115");
		task.divisibleBy25("937826393775889329125");
		task.divisibleBy25("33612315332343");
		task.divisibleBy25("130");
		task.divisibleBy25("3824566134312124250");
	}
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
import Foundation;
/*
    Swift 4 program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	func divisibleBy25(_ data: String)
	{
        let num = Array(data);
		// Get the length of number
		let n: Int = num.count;
		if (n == 0)
		{
			return;
		}
		var result: Bool = false;
		if (n == 1 && num[0] == "0")
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			let value: Int = ((Int(UnicodeScalar(String(num[n - 2]))!.value) -
                               Int(UnicodeScalar(String("0"))!.value)) * 10) + 
              (Int(UnicodeScalar(String(num[n - 1]))!.value) -
               Int(UnicodeScalar(String("0"))!.value));
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			print("\n Number", data ,"is divisible by 25", terminator: "");
		}
		else
		{
			print("\n Number", data ,"is not divisible by 25", terminator: "");
		}
	}
}
func main()
{
	let task: Divisibility = Divisibility();
	// Test Inputs
	task.divisibleBy25("115");
	task.divisibleBy25("937826393775889329125");
	task.divisibleBy25("33612315332343");
	task.divisibleBy25("130");
	task.divisibleBy25("3824566134312124250");
}
main();

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25
/*
    Kotlin program for
    Check if large number is divisible by 25
*/
class Divisibility
{
	fun divisibleBy25(num: String): Unit
	{
		// Get the length of number
		val n: Int = num.length;
		if (n == 0)
		{
			return;
		}
		var result: Boolean = false;
		if (n == 1 && num.get(0) == '0')
		{
			result = true;
		}
		else if (n > 1)
		{
			// Collect a number of last two digits
			val value: Int = ((num.get(n - 2).toInt() - '0'.toInt()) * 10) + 
              (num.get(n - 1).toInt() - '0'.toInt());
			if (value % 25 == 0)
			{
				result = true;
			}
		}
		if (result == true)
		{
			print("\n Number " + num + " is divisible by 25");
		}
		else
		{
			print("\n Number " + num + " is not divisible by 25");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Divisibility = Divisibility();
	// Test Inputs
	task.divisibleBy25("115");
	task.divisibleBy25("937826393775889329125");
	task.divisibleBy25("33612315332343");
	task.divisibleBy25("130");
	task.divisibleBy25("3824566134312124250");
}

Output

 Number 115 is not divisible by 25
 Number 937826393775889329125 is divisible by 25
 Number 33612315332343 is not divisible by 25
 Number 130 is not divisible by 25
 Number 3824566134312124250 is divisible by 25




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.

New Comment