Check if a number is multiple of 5 or not

Here given code implementation process.

// C program
// Check if a number is multiple of 5 or not
// By using modulo operator
#include <stdio.h>

// Check that given number is multiple of 5 or not
void isMultipleOf5(int number)
{
	if ((number % 5) == 0)
	{
		printf(" Number %d is multiple of 5\n", number);
	}
	else
	{
		printf(" Number %d is not multiple of 5\n", number);
	}
}
int main()
{
	// Test
	isMultipleOf5(-5);
	isMultipleOf5(15);
	isMultipleOf5(32);
	isMultipleOf5(20);
	return 0;
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Java Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	public void isMultipleOf5(int number)
	{
		if ((number % 5) == 0)
		{
			System.out.println(" Number " + number + " is multiple of 5");
		}
		else
		{
			System.out.println(" Number " + number + " is not multiple of 5");
		}
	}
	public static void main(String[] args)
	{
		Multiple task = new Multiple();
		// Test
		task.isMultipleOf5(-5);
		task.isMultipleOf5(15);
		task.isMultipleOf5(32);
		task.isMultipleOf5(20);
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
// Include header file
#include <iostream>

using namespace std;
/*
  C++ Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	public:
		// Check that given number is multiple of 5 or not
		void isMultipleOf5(int number)
		{
			if ((number % 5) == 0)
			{
				cout << " Number " << number << " is multiple of 5" << endl;
			}
			else
			{
				cout << " Number " << number << " is not multiple of 5" << endl;
			}
		}
};
int main()
{
	Multiple *task = new Multiple();
	// Test
	task->isMultipleOf5(-5);
	task->isMultipleOf5(15);
	task->isMultipleOf5(32);
	task->isMultipleOf5(20);
	return 0;
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
// Include namespace system
using System;
/*
  Csharp Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
public class Multiple
{
	// Check that given number is multiple of 5 or not
	public void isMultipleOf5(int number)
	{
		if ((number % 5) == 0)
		{
			Console.WriteLine(" Number " + number + " is multiple of 5");
		}
		else
		{
			Console.WriteLine(" Number " + number + " is not multiple of 5");
		}
	}
	public static void Main(String[] args)
	{
		Multiple task = new Multiple();
		// Test
		task.isMultipleOf5(-5);
		task.isMultipleOf5(15);
		task.isMultipleOf5(32);
		task.isMultipleOf5(20);
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
<?php
/*
  Php Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	public	function isMultipleOf5($number)
	{
		if (($number % 5) == 0)
		{
			echo " Number ".$number.
			" is multiple of 5".
			"\n";
		}
		else
		{
			echo " Number ".$number.
			" is not multiple of 5".
			"\n";
		}
	}
}

function main()
{
	$task = new Multiple();
	// Test
	$task->isMultipleOf5(-5);
	$task->isMultipleOf5(15);
	$task->isMultipleOf5(32);
	$task->isMultipleOf5(20);
}
main();

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Node JS Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	isMultipleOf5(number)
	{
		if ((number % 5) == 0)
		{
			console.log(" Number " + number + " is multiple of 5");
		}
		else
		{
			console.log(" Number " + number + " is not multiple of 5");
		}
	}
}

function main()
{
	var task = new Multiple();
	// Test
	task.isMultipleOf5(-5);
	task.isMultipleOf5(15);
	task.isMultipleOf5(32);
	task.isMultipleOf5(20);
}
main();

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
#  Python 3 Program for
#  Check if a number is multiple of 5 or not
#  By using modulo operator
class Multiple :
	#  Check that given number is multiple of 5 or not
	def isMultipleOf5(self, number) :
		if ((number % 5) == 0) :
			print(" Number ", number ," is multiple of 5")
		else :
			print(" Number ", number ," is not multiple of 5")
		
	

def main() :
	task = Multiple()
	#  Test
	task.isMultipleOf5(-5)
	task.isMultipleOf5(15)
	task.isMultipleOf5(32)
	task.isMultipleOf5(20)

if __name__ == "__main__": main()

input

 Number  -5  is multiple of 5
 Number  15  is multiple of 5
 Number  32  is not multiple of 5
 Number  20  is multiple of 5
#  Ruby Program for
#  Check if a number is multiple of 5 or not
#  By using modulo operator
class Multiple 
	#  Check that given number is multiple of 5 or not
	def isMultipleOf5(number) 
		if ((number % 5) == 0) 
			print(" Number ", number ," is multiple of 5", "\n")
		else 
			print(" Number ", number ," is not multiple of 5", "\n")
		end

	end

end

def main() 
	task = Multiple.new()
	#  Test
	task.isMultipleOf5(-5)
	task.isMultipleOf5(15)
	task.isMultipleOf5(32)
	task.isMultipleOf5(20)
end

main()

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Scala Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple()
{
	// Check that given number is multiple of 5 or not
	def isMultipleOf5(number: Int): Unit = {
		if ((number % 5) == 0)
		{
			println(" Number " + number + " is multiple of 5");
		}
		else
		{
			println(" Number " + number + " is not multiple of 5");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Multiple = new Multiple();
		// Test
		task.isMultipleOf5(-5);
		task.isMultipleOf5(15);
		task.isMultipleOf5(32);
		task.isMultipleOf5(20);
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Swift 4 Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	func isMultipleOf5(_ number: Int)
	{
		if ((number % 5) == 0)
		{
			print(" Number ", number ," is multiple of 5");
		}
		else
		{
			print(" Number ", number ," is not multiple of 5");
		}
	}
}
func main()
{
	let task: Multiple = Multiple();
	// Test
	task.isMultipleOf5(-5);
	task.isMultipleOf5(15);
	task.isMultipleOf5(32);
	task.isMultipleOf5(20);
}
main();

input

 Number  -5  is multiple of 5
 Number  15  is multiple of 5
 Number  32  is not multiple of 5
 Number  20  is multiple of 5
/*
  Kotlin Program for
  Check if a number is multiple of 5 or not
  By using modulo operator
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	fun isMultipleOf5(number: Int): Unit
	{
		if ((number % 5) == 0)
		{
			println(" Number " + number + " is multiple of 5");
		}
		else
		{
			println(" Number " + number + " is not multiple of 5");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Multiple = Multiple();
	// Test
	task.isMultipleOf5(-5);
	task.isMultipleOf5(15);
	task.isMultipleOf5(32);
	task.isMultipleOf5(20);
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5

In case given number is form of a string. Then last digit are identified is divisible by 5. Therefore we need to check its last character is equal to 5 or 0s.

// C program
// Check if a number is multiple of 5 or not
// When Number is form of string
#include <stdio.h>
#include <string.h>

// Check that given number is multiple of 5 or not
void isMultipleOf5(const char *number)
{
    int length = strlen(number);

    if (length > 0 && (number[length-1]=='5' || number[length-1]=='0' ))
    {
        printf(" Number %s is multiple of 5\n",number);
    }
    else
    {
        printf(" Number %s is not multiple of 5\n",number);
    }
}
int main()
{
    // Test
    isMultipleOf5("-5");
    isMultipleOf5("15");
    isMultipleOf5("32");
    isMultipleOf5("20");
    return 0;
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Java Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	public void isMultipleOf5(String number)
	{
		int length = number.length();
	if (length > 0 && (number.charAt(length - 1) == '5' 
        || number.charAt(length - 1) == '0'))
		{
			System.out.println(" Number " + number + " is multiple of 5");
		}
		else
		{
			System.out.println(" Number " + number + " is not multiple of 5");
		}
	}
	public static void main(String[] args)
	{
		Multiple task = new Multiple();
		// Test
		task.isMultipleOf5("-5");
		task.isMultipleOf5("15");
		task.isMultipleOf5("32");
		task.isMultipleOf5("20");
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
// Include header file
#include <iostream>

#include <string>

using namespace std;
/*
  C++ Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	public:
		// Check that given number is multiple of 5 or not
		void isMultipleOf5(string number)
		{
			int length = number.length();
			if (length > 0 && (number[length - 1] == '5' || number[length - 1] == '0'))
			{
				cout << " Number " << number << " is multiple of 5" << endl;
			}
			else
			{
				cout << " Number " << number << " is not multiple of 5" << endl;
			}
		}
};
int main()
{
	Multiple *task = new Multiple();
	// Test
	task->isMultipleOf5("-5");
	task->isMultipleOf5("15");
	task->isMultipleOf5("32");
	task->isMultipleOf5("20");
	return 0;
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
// Include namespace system
using System;
/*
  Csharp Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
public class Multiple
{
	// Check that given number is multiple of 5 or not
	public void isMultipleOf5(String number)
	{
		int length = number.Length;
		if (length > 0 && (number[length - 1] == '5' || number[length - 1] == '0'))
		{
			Console.WriteLine(" Number " + number + " is multiple of 5");
		}
		else
		{
			Console.WriteLine(" Number " + number + " is not multiple of 5");
		}
	}
	public static void Main(String[] args)
	{
		Multiple task = new Multiple();
		// Test
		task.isMultipleOf5("-5");
		task.isMultipleOf5("15");
		task.isMultipleOf5("32");
		task.isMultipleOf5("20");
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
<?php
/*
  Php Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	public	function isMultipleOf5($number)
	{
		$length = strlen($number);
		if ($length > 0 && ($number[$length - 1] == '5' || $number[$length - 1] == '0'))
		{
			echo " Number ".$number.
			" is multiple of 5".
			"\n";
		}
		else
		{
			echo " Number ".$number.
			" is not multiple of 5".
			"\n";
		}
	}
}

function main()
{
	$task = new Multiple();
	// Test
	$task->isMultipleOf5("-5");
	$task->isMultipleOf5("15");
	$task->isMultipleOf5("32");
	$task->isMultipleOf5("20");
}
main();

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Node JS Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	isMultipleOf5(number)
	{
		var length = number.length;
		if (length > 0 && (number.charAt(length - 1) == '5' || number.charAt(length - 1) == '0'))
		{
			console.log(" Number " + number + " is multiple of 5");
		}
		else
		{
			console.log(" Number " + number + " is not multiple of 5");
		}
	}
}

function main()
{
	var task = new Multiple();
	// Test
	task.isMultipleOf5("-5");
	task.isMultipleOf5("15");
	task.isMultipleOf5("32");
	task.isMultipleOf5("20");
}
main();

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
#  Python 3 Program for
#  Check if a number is multiple of 5 or not
#  When Number is form of string
class Multiple :
	#  Check that given number is multiple of 5 or not
	def isMultipleOf5(self, number) :
		length = len(number)
		if (length > 0 and(number[length - 1] == '5'
				or number[length - 1] == '0')) :
			print(" Number ", number ," is multiple of 5")
		else :
			print(" Number ", number ," is not multiple of 5")
		
	

def main() :
	task = Multiple()
	#  Test
	task.isMultipleOf5("-5")
	task.isMultipleOf5("15")
	task.isMultipleOf5("32")
	task.isMultipleOf5("20")

if __name__ == "__main__": main()

input

 Number  -5  is multiple of 5
 Number  15  is multiple of 5
 Number  32  is not multiple of 5
 Number  20  is multiple of 5
#  Ruby Program for
#  Check if a number is multiple of 5 or not
#  When Number is form of string
class Multiple 
	#  Check that given number is multiple of 5 or not
	def isMultipleOf5(number) 
		length = number.length
		if (length > 0 && (number[length - 1] == '5' || number[length - 1] == '0')) 
			print(" Number ", number ," is multiple of 5", "\n")
		else 
			print(" Number ", number ," is not multiple of 5", "\n")
		end

	end

end

def main() 
	task = Multiple.new()
	#  Test
	task.isMultipleOf5("-5")
	task.isMultipleOf5("15")
	task.isMultipleOf5("32")
	task.isMultipleOf5("20")
end

main()

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
import scala.collection.mutable._;
/*
  Scala Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple()
{
	// Check that given number is multiple of 5 or not
	def isMultipleOf5(number: String): Unit = {
		var length: Int = number.length();
		if (length > 0 && (number.charAt(length - 1) == '5' || number.charAt(length - 1) == '0'))
		{
			println(" Number " + number + " is multiple of 5");
		}
		else
		{
			println(" Number " + number + " is not multiple of 5");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Multiple = new Multiple();
		// Test
		task.isMultipleOf5("-5");
		task.isMultipleOf5("15");
		task.isMultipleOf5("32");
		task.isMultipleOf5("20");
	}
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5
/*
  Swift 4 Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	func isMultipleOf5(_ num: String )
	{
      	let number = Array(num);
		let length: Int = number.count;
		if (length > 0 && (number[length - 1] == "5" || number[length - 1] == "0"))
		{
			print(" Number ", num ," is multiple of 5");
		}
		else
		{
			print(" Number ", num ," is not multiple of 5");
		}
	}
}
func main()
{
	let task: Multiple = Multiple();
	// Test
	task.isMultipleOf5("-5");
	task.isMultipleOf5("15");
	task.isMultipleOf5("32");
	task.isMultipleOf5("20");
}
main();

input

 Number  -5  is multiple of 5
 Number  15  is multiple of 5
 Number  32  is not multiple of 5
 Number  20  is multiple of 5
/*
  Kotlin Program for
  Check if a number is multiple of 5 or not
  When Number is form of string
*/
class Multiple
{
	// Check that given number is multiple of 5 or not
	fun isMultipleOf5(number: String): Unit
	{
		val length: Int = number.length;
		if (length > 0 && (number.get(length - 1) == '5' || number.get(length - 1) == '0'))
		{
			println(" Number " + number + " is multiple of 5");
		}
		else
		{
			println(" Number " + number + " is not multiple of 5");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Multiple = Multiple();
	// Test
	task.isMultipleOf5("-5");
	task.isMultipleOf5("15");
	task.isMultipleOf5("32");
	task.isMultipleOf5("20");
}

input

 Number -5 is multiple of 5
 Number 15 is multiple of 5
 Number 32 is not multiple of 5
 Number 20 is multiple of 5


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







© 2021, kalkicode.com, All rights reserved