Check whether the given number is moran number or not

Here given code implementation process.

// C program for 
// Check whether the given number is moran number or not
#include <stdio.h>

// Check that whether given number is prime or not
int isPrime(int num)
{
	if (num == 2 || num == 3 || num == 5)
	{
		// Base case
		return 1;
	}
	if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
	{
		return 0;
	}
	int i = 11;
	while ((i *i) <= num)
	{
		if (num % i == 0)
		{
			// When number is divisible of current i value
			return 0;
		}
		else if (num % (i + 2) == 0)
		{
			// When number is divisible of current i + 2 value
			return 0;
		}
		i = i + 6;
	}
	return 1;
}
void isMoranNo(int number)
{
	int n = number;
	int sum = 0;
	// Sum of digit
	while (n != 0)
	{
		sum = sum + (n % 10);
		n = n / 10;
	}
	if ((number % sum) == 0 && isPrime(number / sum))
	{
		// When sum of digits is divisible by number and its 
		// remainder is zero and number divisible by digit sum is an prime number.
		printf(" Number %d is moran number\n", number);
	}
	else
	{
		printf(" Number %d is not moran number\n", number);
	}
}
int main(int argc, char
	const *argv[])
{
	// Test Cases
	isMoranNo(27);
	isMoranNo(161);
	isMoranNo(111);
	isMoranNo(151);
	isMoranNo(84);
	return 0;
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
/*
  Java Program for
  Check whether the given number is moran number or not
*/
public class MoranNumber
{
	// Check that whether given number is prime or not
	public boolean isPrime(int num)
	{
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		int i = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else if (num % (i + 2) == 0)
			{
				// When number is divisible of current i + 2 value
				return false;
			}
			i = i + 6;
		}
		return true;
	}
	public void isMoranNo(int number)
	{
		int n = number;
		int sum = 0;
		// Sum of digits in given number
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}
		if ((number % sum) == 0 && isPrime(number / sum))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
            // sum is an prime number.
			System.out.println(" Number " + number + " is moran number");
		}
		else
		{
			System.out.println(" Number " + number + " is not moran number");
		}
	}
	public static void main(String[] args)
	{
		MoranNumber task = new MoranNumber();
		// Test Cases
		task.isMoranNo(27);
		task.isMoranNo(161);
		task.isMoranNo(111);
		task.isMoranNo(151);
		task.isMoranNo(84);
	}
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
// Include header file
#include <iostream>

using namespace std;
/*
  C++ Program for
  Check whether the given number is moran number or not
*/
class MoranNumber
{
	public:
		// Check that whether given number is prime or not
		bool isPrime(int num)
		{
			if (num == 2 || num == 3 || num == 5)
			{
				// Base case
				return true;
			}
			if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
			{
				return false;
			}
			int i = 11;
			while ((i *i) <= num)
			{
				if (num % i == 0)
				{
					// When number is divisible of current i value
					return false;
				}
				else
				{
					if (num % (i + 2) == 0)
					{
						// When number is divisible of current i + 2 value
						return false;
					}
				}
				i = i + 6;
			}
			return true;
		}
	void isMoranNo(int number)
	{
		int n = number;
		int sum = 0;
		// Sum of digits in given number
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}
		if ((number % sum) == 0 && this->isPrime(number / sum))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			cout << " Number " << number << " is moran number" << endl;
		}
		else
		{
			cout << " Number " << number << " is not moran number" << endl;
		}
	}
};
int main()
{
	MoranNumber *task = new MoranNumber();
	// Test Cases
	task->isMoranNo(27);
	task->isMoranNo(161);
	task->isMoranNo(111);
	task->isMoranNo(151);
	task->isMoranNo(84);
	return 0;
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
// Include namespace system
using System;
/*
  Csharp Program for
  Check whether the given number is moran number or not
*/
public class MoranNumber
{
	// Check that whether given number is prime or not
	public Boolean isPrime(int num)
	{
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		int i = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if (num % (i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			i = i + 6;
		}
		return true;
	}
	public void isMoranNo(int number)
	{
		int n = number;
		int sum = 0;
		// Sum of digits in given number
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}
		if ((number % sum) == 0 && this.isPrime(number / sum))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			Console.WriteLine(" Number " + number + " is moran number");
		}
		else
		{
			Console.WriteLine(" Number " + number + " is not moran number");
		}
	}
	public static void Main(String[] args)
	{
		MoranNumber task = new MoranNumber();
		// Test Cases
		task.isMoranNo(27);
		task.isMoranNo(161);
		task.isMoranNo(111);
		task.isMoranNo(151);
		task.isMoranNo(84);
	}
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
<?php
/*
  Php Program for
  Check whether the given number is moran number or not
*/
class MoranNumber
{
	// Check that whether given number is prime or not
	public	function isPrime($num)
	{
		if ($num == 2 || $num == 3 || $num == 5)
		{
			// Base case
			return true;
		}
		if ($num <= 1 || ($num % 2 == 0) || ($num % 3 == 0) || ($num % 5 == 0))
		{
			return false;
		}
		$i = 11;
		while (($i * $i) <= $num)
		{
			if ($num % $i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if ($num % ($i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			$i = $i + 6;
		}
		return true;
	}
	public	function isMoranNo($number)
	{
		$n = $number;
		$sum = 0;
		// Sum of digits in given number
		while ($n != 0)
		{
			$sum = $sum + ($n % 10);
			$n = (int)($n / 10);
		}
		if (($number % $sum) == 0 && $this->isPrime((int)($number / $sum)))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			echo " Number ".$number.
			" is moran number".
			"\n";
		}
		else
		{
			echo " Number ".$number.
			" is not moran number".
			"\n";
		}
	}
}

function main()
{
	$task = new MoranNumber();
	// Test Cases
	$task->isMoranNo(27);
	$task->isMoranNo(161);
	$task->isMoranNo(111);
	$task->isMoranNo(151);
	$task->isMoranNo(84);
}
main();

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
/*
  Node JS Program for
  Check whether the given number is moran number or not
*/
class MoranNumber
{
	// Check that whether given number is prime or not
	isPrime(num)
	{
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		var i = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if (num % (i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			i = i + 6;
		}
		return true;
	}
	isMoranNo(number)
	{
		var n = number;
		var sum = 0;
		// Sum of digits in given number
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = parseInt(n / 10);
		}
		if ((number % sum) == 0 && this.isPrime(parseInt(number / sum)))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			console.log(" Number " + number + " is moran number");
		}
		else
		{
			console.log(" Number " + number + " is not moran number");
		}
	}
}

function main()
{
	var task = new MoranNumber();
	// Test Cases
	task.isMoranNo(27);
	task.isMoranNo(161);
	task.isMoranNo(111);
	task.isMoranNo(151);
	task.isMoranNo(84);
}
main();

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
#  Python 3 Program for
#  Check whether the given number is moran number or not
class MoranNumber :
	#  Check that whether given number is prime or not
	def isPrime(self, num) :
		if (num == 2 or num == 3 or num == 5) :
			#  Base case
			return True
		
		if (num <= 1 or(num % 2 == 0) or(num % 3 == 0) or(num % 5 == 0)) :
			return False
		
		i = 11
		while ((i * i) <= num) :
			if (num % i == 0) :
				#  When number is divisible of current i value
				return False
			else :
				if (num % (i + 2) == 0) :
					#  When number is divisible of current i + 2 value
					return False
				
			
			i = i + 6
		
		return True
	
	def isMoranNo(self, number) :
		n = number
		sum = 0
		#  Sum of digits in given number
		while (n != 0) :
			sum = sum + (n % 10)
			n = int(n / 10)
		
		if ((number % sum) == 0 and self.isPrime(int(number / sum))) :
			#  When sum of digits is divisible by number and its 
			#  remainder is zero and number divisible by digit 
			#  sum is an prime number.
			print(" Number ", number ," is moran number")
		else :
			print(" Number ", number ," is not moran number")
		
	

def main() :
	task = MoranNumber()
	#  Test Cases
	task.isMoranNo(27)
	task.isMoranNo(161)
	task.isMoranNo(111)
	task.isMoranNo(151)
	task.isMoranNo(84)

if __name__ == "__main__": main()

input

 Number  27  is moran number
 Number  161  is not moran number
 Number  111  is moran number
 Number  151  is not moran number
 Number  84  is moran number
#  Ruby Program for
#  Check whether the given number is moran number or not
class MoranNumber 
	#  Check that whether given number is prime or not
	def isPrime(num) 
		if (num == 2 || num == 3 || num == 5) 
			#  Base case
			return true
		end

		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0)) 
			return false
		end

		i = 11
		while ((i * i) <= num) 
			if (num % i == 0) 
				#  When number is divisible of current i value
				return false
			else 
				if (num % (i + 2) == 0) 
					#  When number is divisible of current i + 2 value
					return false
				end

			end

			i = i + 6
		end

		return true
	end

	def isMoranNo(number) 
		n = number
		sum = 0
		#  Sum of digits in given number
		while (n != 0) 
			sum = sum + (n % 10)
			n = n / 10
		end

		if ((number % sum) == 0 && self.isPrime(number / sum)) 
			#  When sum of digits is divisible by number and its 
			#  remainder is zero and number divisible by digit 
			#  sum is an prime number.
			print(" Number ", number ," is moran number", "\n")
		else 
			print(" Number ", number ," is not moran number", "\n")
		end

	end

end

def main() 
	task = MoranNumber.new()
	#  Test Cases
	task.isMoranNo(27)
	task.isMoranNo(161)
	task.isMoranNo(111)
	task.isMoranNo(151)
	task.isMoranNo(84)
end

main()

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
/*
  Scala Program for
  Check whether the given number is moran number or not
*/
class MoranNumber()
{
	// Check that whether given number is prime or not
	def isPrime(num: Int): Boolean = {
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		var i: Int = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if (num % (i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			i = i + 6;
		}
		return true;
	}
	def isMoranNo(number: Int): Unit = {
		var n: Int = number;
		var sum: Int = 0;
		// Sum of digits in given number
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = (n / 10).toInt;
		}
		if ((number % sum) == 0 && isPrime((number / sum).toInt))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			println(" Number " + number + " is moran number");
		}
		else
		{
			println(" Number " + number + " is not moran number");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: MoranNumber = new MoranNumber();
		// Test Cases
		task.isMoranNo(27);
		task.isMoranNo(161);
		task.isMoranNo(111);
		task.isMoranNo(151);
		task.isMoranNo(84);
	}
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number
/*
  Swift 4 Program for
  Check whether the given number is moran number or not
*/
class MoranNumber
{
	// Check that whether given number is prime or not
	func isPrime(_ num: Int)->Bool
	{
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		var i: Int = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if (num % (i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			i = i + 6;
		}
		return true;
	}
	func isMoranNo(_ number: Int)
	{
		var n: Int = number;
		var sum: Int = 0;
		// Sum of digits in given number
		while (n  != 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}
		if ((number % sum) == 0 && self.isPrime(number / sum))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			print(" Number ", number ," is moran number");
		}
		else
		{
			print(" Number ", number ," is not moran number");
		}
	}
}
func main()
{
	let task: MoranNumber = MoranNumber();
	// Test Cases
	task.isMoranNo(27);
	task.isMoranNo(161);
	task.isMoranNo(111);
	task.isMoranNo(151);
	task.isMoranNo(84);
}
main();

input

 Number  27  is moran number
 Number  161  is not moran number
 Number  111  is moran number
 Number  151  is not moran number
 Number  84  is moran number
/*
  Kotlin Program for
  Check whether the given number is moran number or not
*/
class MoranNumber
{
	// Check that whether given number is prime or not
	fun isPrime(num: Int): Boolean
	{
		if (num == 2 || num == 3 || num == 5)
		{
			// Base case
			return true;
		}
		if (num <= 1 || (num % 2 == 0) || (num % 3 == 0) || (num % 5 == 0))
		{
			return false;
		}
		var i: Int = 11;
		while ((i * i) <= num)
		{
			if (num % i == 0)
			{
				// When number is divisible of current i value
				return false;
			}
			else
			{
				if (num % (i + 2) == 0)
				{
					// When number is divisible of current i + 2 value
					return false;
				}
			}
			i = i + 6;
		}
		return true;
	}
	fun isMoranNo(number: Int): Unit
	{
		var n: Int = number;
		var sum: Int = 0;
		while (n != 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}
		if ((number % sum) == 0 && this.isPrime(number / sum))
		{
			// When sum of digits is divisible by number and its 
			// remainder is zero and number divisible by digit 
			// sum is an prime number.
			println(" Number " + number + " is moran number");
		}
		else
		{
			println(" Number " + number + " is not moran number");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: MoranNumber = MoranNumber();
	// Test Cases
	task.isMoranNo(27);
	task.isMoranNo(161);
	task.isMoranNo(111);
	task.isMoranNo(151);
	task.isMoranNo(84);
}

input

 Number 27 is moran number
 Number 161 is not moran number
 Number 111 is moran number
 Number 151 is not moran number
 Number 84 is moran number

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