Self dividing numbers

Here given code implementation process.

/*
    C program for
    Self dividing numbers
*/
#include <stdio.h>

void isSelfDivisible(int num)
{
	int temp = num;
	int result = 1;
	if (num > 0)
	{
		while (temp > 0 && result == 1)
		{
			if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
			{
				// When numbers are contains zero or
				// number digit is not divisible itself
				result = 0;
			}
			else
			{
				// Remove last digit
				temp = temp / 10;
			}
		}
	}
	else
	{
		result = 0;
	}
	printf("\n Given Number : %d", num);
	if (result == 1)
	{
		printf("\n Is Self Divisible Number");
	}
	else
	{
		printf("\n Is Not Self Divisible Number");
	}
}
int main(int argc, char
	const *argv[])
{
	// Test
	isSelfDivisible(12);
	isSelfDivisible(19);
	isSelfDivisible(728);
	isSelfDivisible(23);
	return 0;
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
/*
    Java program for
    Self dividing numbers
*/
public class Divisible
{
    public void isSelfDivisible(int num)
    {
        int temp = num;
        boolean result = true;
        if (num > 0)
        {
            while (temp > 0 && result == true)
            {
                if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
                {
                    // When numbers are contains zero or
                    // number digit is not divisible itself
                    result = false;
                }
                else
                {
                    // Remove last digit
                    temp = temp / 10;
                }
            }
        }
        else
        {
            result = false;
        }
        System.out.print("\n Given Number : " + num );
        if (result == true)
        {
            System.out.print("\n Is Self Divisible Number");
        }
        else
        {
            System.out.print("\n Is Not Self Divisible Number");
        }
    }

    public static void main(String[] args)
    {
        Divisible task = new Divisible();
        // Test
        task.isSelfDivisible(12);
        task.isSelfDivisible(19);
        task.isSelfDivisible(728);
        task.isSelfDivisible(23);

    }
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
// Include header file
#include <iostream>
using namespace std;
/*
    C++ program for
    Self dividing numbers
*/
class Divisible
{
	public: void isSelfDivisible(int num)
	{
		int temp = num;
		bool result = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = temp / 10;
				}
			}
		}
		else
		{
			result = false;
		}
		cout << "\n Given Number : " << num;
		if (result == true)
		{
			cout << "\n Is Self Divisible Number";
		}
		else
		{
			cout << "\n Is Not Self Divisible Number";
		}
	}
};
int main()
{
	Divisible *task = new Divisible();
	// Test
	task->isSelfDivisible(12);
	task->isSelfDivisible(19);
	task->isSelfDivisible(728);
	task->isSelfDivisible(23);
	return 0;
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
// Include namespace system
using System;
/*
    Csharp program for
    Self dividing numbers
*/
public class Divisible
{
	public void isSelfDivisible(int num)
	{
		int temp = num;
		Boolean result = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = temp / 10;
				}
			}
		}
		else
		{
			result = false;
		}
		Console.Write("\n Given Number : " + num);
		if (result == true)
		{
			Console.Write("\n Is Self Divisible Number");
		}
		else
		{
			Console.Write("\n Is Not Self Divisible Number");
		}
	}
	public static void Main(String[] args)
	{
		Divisible task = new Divisible();
		// Test
		task.isSelfDivisible(12);
		task.isSelfDivisible(19);
		task.isSelfDivisible(728);
		task.isSelfDivisible(23);
	}
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
package main
import "fmt"
/*
    Go program for
    Self dividing numbers
*/

func isSelfDivisible(num int) {
	var temp int = num
	var result bool = true
	if num > 0 {
		for (temp > 0 && result == true) {
			if ((temp % 10) == 0) || ((num % (temp % 10)) != 0) {
				// When numbers are contains zero or
				// number digit is not divisible itself
				result = false
			} else {
				// Remove last digit
				temp = temp / 10
			}
		}
	} else {
		result = false
	}
	fmt.Print("\n Given Number : ", num)
	if result == true {
		fmt.Print("\n Is Self Divisible Number")
	} else {
		fmt.Print("\n Is Not Self Divisible Number")
	}
}
func main() {

	// Test
	isSelfDivisible(12)
	isSelfDivisible(19)
	isSelfDivisible(728)
	isSelfDivisible(23)
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
<?php
/*
    Php program for
    Self dividing numbers
*/
class Divisible
{
	public	function isSelfDivisible($num)
	{
		$temp = $num;
		$result = true;
		if ($num > 0)
		{
			while ($temp > 0 && $result == true)
			{
				if ((($temp % 10) == 0) || (($num % ($temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					$result = false;
				}
				else
				{
					// Remove last digit
					$temp = (int)($temp / 10);
				}
			}
		}
		else
		{
			$result = false;
		}
		echo("\n Given Number : ".$num);
		if ($result == true)
		{
			echo("\n Is Self Divisible Number");
		}
		else
		{
			echo("\n Is Not Self Divisible Number");
		}
	}
}

function main()
{
	$task = new Divisible();
	// Test
	$task->isSelfDivisible(12);
	$task->isSelfDivisible(19);
	$task->isSelfDivisible(728);
	$task->isSelfDivisible(23);
}
main();

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
/*
    Node JS program for
    Self dividing numbers
*/
class Divisible
{
	isSelfDivisible(num)
	{
		var temp = num;
		var result = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = parseInt(temp / 10);
				}
			}
		}
		else
		{
			result = false;
		}
		process.stdout.write("\n Given Number : " + num);
		if (result == true)
		{
			process.stdout.write("\n Is Self Divisible Number");
		}
		else
		{
			process.stdout.write("\n Is Not Self Divisible Number");
		}
	}
}

function main()
{
	var task = new Divisible();
	// Test
	task.isSelfDivisible(12);
	task.isSelfDivisible(19);
	task.isSelfDivisible(728);
	task.isSelfDivisible(23);
}
main();

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
#    Python 3 program for
#    Self dividing numbers
class Divisible :
	def isSelfDivisible(self, num) :
		temp = num
		result = True
		if (num > 0) :
			while (temp > 0 and result == True) :
				if (((temp % 10) == 0) or((num % (temp % 10)) != 0)) :
					#  When numbers are contains zero or
					#  number digit is not divisible itself
					result = False
				else :
					#  Remove last digit
					temp = int(temp / 10)
				
			
		else :
			result = False
		
		print("\n Given Number : ", num, end = "")
		if (result == True) :
			print("\n Is Self Divisible Number", end = "")
		else :
			print("\n Is Not Self Divisible Number", end = "")
		
	

def main() :
	task = Divisible()
	#  Test
	task.isSelfDivisible(12)
	task.isSelfDivisible(19)
	task.isSelfDivisible(728)
	task.isSelfDivisible(23)

if __name__ == "__main__": main()

Output

 Given Number :  12
 Is Self Divisible Number
 Given Number :  19
 Is Not Self Divisible Number
 Given Number :  728
 Is Self Divisible Number
 Given Number :  23
 Is Not Self Divisible Number
#    Ruby program for
#    Self dividing numbers
class Divisible 
	def isSelfDivisible(num) 
		temp = num
		result = true
		if (num > 0) 
			while (temp > 0 && result == true) 
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0)) 
					#  When numbers are contains zero or
					#  number digit is not divisible itself
					result = false
				else
 
					#  Remove last digit
					temp = temp / 10
				end

			end

		else
 
			result = false
		end

		print("\n Given Number : ", num)
		if (result == true) 
			print("\n Is Self Divisible Number")
		else
 
			print("\n Is Not Self Divisible Number")
		end

	end

end

def main() 
	task = Divisible.new()
	#  Test
	task.isSelfDivisible(12)
	task.isSelfDivisible(19)
	task.isSelfDivisible(728)
	task.isSelfDivisible(23)
end

main()

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
/*
    Scala program for
    Self dividing numbers
*/
class Divisible()
{
	def isSelfDivisible(num: Int): Unit = {
		var temp: Int = num;
		var result: Boolean = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = temp / 10;
				}
			}
		}
		else
		{
			result = false;
		}
		print("\n Given Number : " + num);
		if (result == true)
		{
			print("\n Is Self Divisible Number");
		}
		else
		{
			print("\n Is Not Self Divisible Number");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Divisible = new Divisible();
		// Test
		task.isSelfDivisible(12);
		task.isSelfDivisible(19);
		task.isSelfDivisible(728);
		task.isSelfDivisible(23);
	}
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible Number
/*
    Swift 4 program for
    Self dividing numbers
*/
class Divisible
{
	func isSelfDivisible(_ num: Int)
	{
		var temp: Int = num;
		var result: Bool = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10))  != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = temp / 10;
				}
			}
		}
		else
		{
			result = false;
		}
		print("\n Given Number : ", num, terminator: "");
		if (result == true)
		{
			print("\n Is Self Divisible Number", terminator: "");
		}
		else
		{
			print("\n Is Not Self Divisible Number", terminator: "");
		}
	}
}
func main()
{
	let task: Divisible = Divisible();
	// Test
	task.isSelfDivisible(12);
	task.isSelfDivisible(19);
	task.isSelfDivisible(728);
	task.isSelfDivisible(23);
}
main();

Output

 Given Number :  12
 Is Self Divisible Number
 Given Number :  19
 Is Not Self Divisible Number
 Given Number :  728
 Is Self Divisible Number
 Given Number :  23
 Is Not Self Divisible Number
/*
    Kotlin program for
    Self dividing numbers
*/
class Divisible
{
	fun isSelfDivisible(num: Int): Unit
	{
		var temp: Int = num;
		var result: Boolean = true;
		if (num > 0)
		{
			while (temp > 0 && result == true)
			{
				if (((temp % 10) == 0) || ((num % (temp % 10)) != 0))
				{
					// When numbers are contains zero or
					// number digit is not divisible itself
					result = false;
				}
				else
				{
					// Remove last digit
					temp = temp / 10;
				}
			}
		}
		else
		{
			result = false;
		}
		print("\n Given Number : " + num);
		if (result == true)
		{
			print("\n Is Self Divisible Number");
		}
		else
		{
			print("\n Is Not Self Divisible Number");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Divisible = Divisible();
	// Test
	task.isSelfDivisible(12);
	task.isSelfDivisible(19);
	task.isSelfDivisible(728);
	task.isSelfDivisible(23);
}

Output

 Given Number : 12
 Is Self Divisible Number
 Given Number : 19
 Is Not Self Divisible Number
 Given Number : 728
 Is Self Divisible Number
 Given Number : 23
 Is Not Self Divisible 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