Nelson Number Program

Here given code implementation process.

// C program
// Nelson Number Program 
#include <stdio.h>

// Determine that given number is Nelson Number or not
void isNelsonNo(int number)
{
	if ((number % 111) == 0)
	{
		// When number is nelson
		printf(" %d is nelson number \n", number);
	}
	else
	{
		printf(" %d is not nelson number \n", number);
	}
}
int main()
{
	// Test Case
	isNelsonNo(444);
	isNelsonNo(113);
	isNelsonNo(333);
	return 0;
}

input

 444 is nelson number
 113 is not nelson number
 333 is nelson number
/*
  Java Program for
  Nelson Number 
*/
class NelsonNo
{
	// Determine that given number is Nelson Number or not
	public void isNelsonNo(int number)
	{
		if ((number % 111) == 0)
		{
			// When number is nelson
			System.out.println(" [" + number + "] is nelson number");
		}
		else
		{
			System.out.println(" [" + number + "] is not nelson number");
		}
	}
	public static void main(String[] args)
	{
		NelsonNo task = new NelsonNo();
		// Test Case
		task.isNelsonNo(444);
		task.isNelsonNo(113);
		task.isNelsonNo(333);
	}
}

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
// Include header file
#include <iostream>
using namespace std;

/*
  C++ Program for
  Nelson Number 
*/

class NelsonNo
{
	public:
		// Determine that given number is Nelson Number or not
		void isNelsonNo(int number)
		{
			if ((number % 111) == 0)
			{
				// When number is nelson
				cout << " [" << number << "] is nelson number" << endl;
			}
			else
			{
				cout << " [" << number << "] is not nelson number" << endl;
			}
		}
};
int main()
{
	NelsonNo *task = new NelsonNo();
	// Test Case
	task->isNelsonNo(444);
	task->isNelsonNo(113);
	task->isNelsonNo(333);
	return 0;
}

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
// Include namespace system
using System;
/*
  Csharp Program for
  Nelson Number 
*/
public class NelsonNo
{
	// Determine that given number is Nelson Number or not
	public void isNelsonNo(int number)
	{
		if ((number % 111) == 0)
		{
			// When number is nelson
			Console.WriteLine(" [" + number + "] is nelson number");
		}
		else
		{
			Console.WriteLine(" [" + number + "] is not nelson number");
		}
	}
	public static void Main(String[] args)
	{
		NelsonNo task = new NelsonNo();
		// Test Case
		task.isNelsonNo(444);
		task.isNelsonNo(113);
		task.isNelsonNo(333);
	}
}

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
<?php
/*
  Php Program for
  Nelson Number 
*/
class NelsonNo
{
	// Determine that given number is Nelson Number or not
	public	function isNelsonNo($number)
	{
		if (($number % 111) == 0)
		{
			// When number is nelson
			echo " [".$number.
			"] is nelson number".
			"\n";
		}
		else
		{
			echo " [".$number.
			"] is not nelson number".
			"\n";
		}
	}
}

function main()
{
	$task = new NelsonNo();
	// Test Case
	$task->isNelsonNo(444);
	$task->isNelsonNo(113);
	$task->isNelsonNo(333);
}
main();

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
/*
  Node JS Program for
  Nelson Number 
*/
class NelsonNo
{
	// Determine that given number is Nelson Number or not
	isNelsonNo(number)
	{
		if ((number % 111) == 0)
		{
			// When number is nelson
			console.log(" [" + number + "] is nelson number");
		}
		else
		{
			console.log(" [" + number + "] is not nelson number");
		}
	}
}

function main()
{
	var task = new NelsonNo();
	// Test Case
	task.isNelsonNo(444);
	task.isNelsonNo(113);
	task.isNelsonNo(333);
}
main();

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
#  Python 3 Program for
#  Nelson Number 
class NelsonNo :
	#  Determine that given number is Nelson Number or not
	def isNelsonNo(self, number) :
		if ((number % 111) == 0) :
			#  When number is nelson
			print(" [", number ,"] is nelson number")
		else :
			print(" [", number ,"] is not nelson number")
		
	

def main() :
	task = NelsonNo()
	#  Test Case
	task.isNelsonNo(444)
	task.isNelsonNo(113)
	task.isNelsonNo(333)

if __name__ == "__main__": main()

input

 [ 444 ] is nelson number
 [ 113 ] is not nelson number
 [ 333 ] is nelson number
#  Ruby Program for
#  Nelson Number 
class NelsonNo 
	#  Determine that given number is Nelson Number or not
	def isNelsonNo(number) 
		if ((number % 111) == 0) 
			#  When number is nelson
			print(" [", number ,"] is nelson number", "\n")
		else 
			print(" [", number ,"] is not nelson number", "\n")
		end

	end

end

def main() 
	task = NelsonNo.new()
	#  Test Case
	task.isNelsonNo(444)
	task.isNelsonNo(113)
	task.isNelsonNo(333)
end

main()

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
/*
  Scala Program for
  Nelson Number 
*/
class NelsonNo()
{
	// Determine that given number is Nelson Number or not
	def isNelsonNo(number: Int): Unit = {
		if ((number % 111) == 0)
		{
			// When number is nelson
			println(" [" + number + "] is nelson number");
		}
		else
		{
			println(" [" + number + "] is not nelson number");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: NelsonNo = new NelsonNo();
		// Test Case
		task.isNelsonNo(444);
		task.isNelsonNo(113);
		task.isNelsonNo(333);
	}
}

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson number
/*
  Swift 4 Program for
  Nelson Number 
*/
class NelsonNo
{
	// Determine that given number is Nelson Number or not
	func isNelsonNo(_ number: Int)
	{
		if ((number % 111) == 0)
		{
			// When number is nelson
			print(" [", number ,"] is nelson number");
		}
		else
		{
			print(" [", number ,"] is not nelson number");
		}
	}
}
func main()
{
	let task: NelsonNo = NelsonNo();
	// Test Case
	task.isNelsonNo(444);
	task.isNelsonNo(113);
	task.isNelsonNo(333);
}
main();

input

 [ 444 ] is nelson number
 [ 113 ] is not nelson number
 [ 333 ] is nelson number
/*
  Kotlin Program for
  Nelson Number 
*/
class NelsonNo
{
	// Determine that given number is Nelson Number or not
	fun isNelsonNo(number: Int): Unit
	{
		if ((number % 111) == 0)
		{
			// When number is nelson
			println(" [" + number + "] is nelson number");
		}
		else
		{
			println(" [" + number + "] is not nelson number");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: NelsonNo = NelsonNo();
	// Test Case
	task.isNelsonNo(444);
	task.isNelsonNo(113);
	task.isNelsonNo(333);
}

input

 [444] is nelson number
 [113] is not nelson number
 [333] is nelson 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