Check whether a given number is even or odd

Here given code implementation process.

// C Program 
// Check whether a given number is even or odd
#include <stdio.h>
 // Determine whether given number is Even or Odd
void checkEvenOdd(int num)
{
	// Display given number
	printf("\n Number : %d", num);
	if (num % 2 == 0)
	{
		// When last bit is not set
		printf("\n Is Even Number \n");
	}
	else
	{
		printf("\n Is Odd Number\n");
	}
}
int main(int argc, char
	const *argv[])
{
	// Test Cases
	// 12 (1100)
	checkEvenOdd(12);
	// 34 (100010)
	checkEvenOdd(34);
	// -12 (∞11110100)
	checkEvenOdd(-12);
	// 7 (111)
	checkEvenOdd(7);
	// 21 (00010101)
	checkEvenOdd(21);
	// -11 (11110101)
	checkEvenOdd(-11);
	return 0;
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
/*
  Java Program 
  Check whether a given number is even or odd
*/
public class Comparison
{
    // Determine whether given number is Even or Odd
    public void checkEvenOdd(int num)
    {
        // Display given number
        System.out.print("\n Number : " + num );
        if (num % 2 == 0)
        {
            // When last bit is not set
            System.out.print("\n Is Even Number \n");
        }
        else
        {
            System.out.print("\n Is Odd Number\n");
        }
    }
    public static void main(String[] args)
    {
        Comparison task = new Comparison();
        // Test Cases
        // 12 (1100)
        task.checkEvenOdd(12);
        // 34 (100010)
        task.checkEvenOdd(34);
        // -12 (∞11110100)
        task.checkEvenOdd(-12);
        // 7 (111)
        task.checkEvenOdd(7);
        // 21 (00010101)
        task.checkEvenOdd(21);
        // -11 (11110101)
        task.checkEvenOdd(-11);
    }
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
// Include header file
#include <iostream>

using namespace std;
/*
  C++ Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	public:
		// Determine whether given number is Even or Odd
		void checkEvenOdd(int num)
		{
			// Display given number
			cout << "\n Number : " << num;
			if (num % 2 == 0)
			{
				// When last bit is not set
				cout << "\n Is Even Number \n";
			}
			else
			{
				cout << "\n Is Odd Number\n";
			}
		}
};
int main()
{
	Comparison task = Comparison();
	// Test Cases
	// 12 (1100)
	task.checkEvenOdd(12);
	// 34 (100010)
	task.checkEvenOdd(34);
	// -12 (∞11110100)
	task.checkEvenOdd(-12);
	// 7 (111)
	task.checkEvenOdd(7);
	// 21 (00010101)
	task.checkEvenOdd(21);
	// -11 (11110101)
	task.checkEvenOdd(-11);
	return 0;
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
// Include namespace system
using System;
/*
  C# Program 
  Check whether a given number is even or odd
*/
public class Comparison
{
	// Determine whether given number is Even or Odd
	public void checkEvenOdd(int num)
	{
		// Display given number
		Console.Write("\n Number : " + num);
		if (num % 2 == 0)
		{
			// When last bit is not set
			Console.Write("\n Is Even Number \n");
		}
		else
		{
			Console.Write("\n Is Odd Number\n");
		}
	}
	public static void Main(String[] args)
	{
		Comparison task = new Comparison();
		// Test Cases
		// 12 (1100)
		task.checkEvenOdd(12);
		// 34 (100010)
		task.checkEvenOdd(34);
		// -12 (∞11110100)
		task.checkEvenOdd(-12);
		// 7 (111)
		task.checkEvenOdd(7);
		// 21 (00010101)
		task.checkEvenOdd(21);
		// -11 (11110101)
		task.checkEvenOdd(-11);
	}
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
<?php
/*
  Php Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	// Determine whether given number is Even or Odd
	public	function checkEvenOdd($num)
	{
		// Display given number
		echo "\n Number : ". $num;
		if ($num % 2 == 0)
		{
			// When last bit is not set
			echo "\n Is Even Number \n";
		}
		else
		{
			echo "\n Is Odd Number\n";
		}
	}
}

function main()
{
	$task = new Comparison();
	// Test Cases
	// 12 (1100)
	$task->checkEvenOdd(12);
	// 34 (100010)
	$task->checkEvenOdd(34);
	// -12 (∞11110100)
	$task->checkEvenOdd(-12);
	// 7 (111)
	$task->checkEvenOdd(7);
	// 21 (00010101)
	$task->checkEvenOdd(21);
	// -11 (11110101)
	$task->checkEvenOdd(-11);
}
main();

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
/*
  Node Js Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	// Determine whether given number is Even or Odd
	checkEvenOdd(num)
	{
		// Display given number
		process.stdout.write("\n Number : " + num);
		if (num % 2 == 0)
		{
			// When last bit is not set
			process.stdout.write("\n Is Even Number \n");
		}
		else
		{
			process.stdout.write("\n Is Odd Number\n");
		}
	}
}

function main()
{
	var task = new Comparison();
	// Test Cases
	// 12 (1100)
	task.checkEvenOdd(12);
	// 34 (100010)
	task.checkEvenOdd(34);
	// -12 (∞11110100)
	task.checkEvenOdd(-12);
	// 7 (111)
	task.checkEvenOdd(7);
	// 21 (00010101)
	task.checkEvenOdd(21);
	// -11 (11110101)
	task.checkEvenOdd(-11);
}
main();

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
#   Python 3 Program 
#   Check whether a given number is even or odd

class Comparison :
	#  Determine whether given number is Even or Odd
	def checkEvenOdd(self, num) :
		#  Display given number
		print("\n Number : ", num, end = "")
		if (num % 2 == 0) :
			#  When last bit is not set
			print("\n Is Even Number ")
		else :
			print("\n Is Odd Number")
		
	

def main() :
	task = Comparison()
	#  Test Cases
	#  12 (1100)
	task.checkEvenOdd(12)
	#  34 (100010)
	task.checkEvenOdd(34)
	#  -12 (∞11110100)
	task.checkEvenOdd(-12)
	#  7 (111)
	task.checkEvenOdd(7)
	#  21 (00010101)
	task.checkEvenOdd(21)
	#  -11 (11110101)
	task.checkEvenOdd(-11)

if __name__ == "__main__": main()

Output

 Number :  12
 Is Even Number

 Number :  34
 Is Even Number

 Number :  -12
 Is Even Number

 Number :  7
 Is Odd Number

 Number :  21
 Is Odd Number

 Number :  -11
 Is Odd Number
#   Ruby Program 
#   Check whether a given number is even or odd

class Comparison 
	#  Determine whether given number is Even or Odd
	def checkEvenOdd(num) 
		#  Display given number
		print("\n Number : ", num)
		if (num % 2 == 0) 
			#  When last bit is not set
			print("\n Is Even Number \n")
		else 
			print("\n Is Odd Number\n")
		end

	end

end

def main() 
	task = Comparison.new()
	#  Test Cases
	#  12 (1100)
	task.checkEvenOdd(12)
	#  34 (100010)
	task.checkEvenOdd(34)
	#  -12 (∞11110100)
	task.checkEvenOdd(-12)
	#  7 (111)
	task.checkEvenOdd(7)
	#  21 (00010101)
	task.checkEvenOdd(21)
	#  -11 (11110101)
	task.checkEvenOdd(-11)
end

main()

Output

 Number : 12
 Is Even Number 

 Number : 34
 Is Even Number 

 Number : -12
 Is Even Number 

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
/*
  Scala Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	// Determine whether given number is Even or Odd
	def checkEvenOdd(num: Int): Unit = {
		// Display given number
		print("\n Number : " + num);
		if (num % 2 == 0)
		{
			// When last bit is not set
			print("\n Is Even Number \n");
		}
		else
		{
			print("\n Is Odd Number\n");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Comparison = new Comparison();
		// Test Cases
		// 12 (1100)
		task.checkEvenOdd(12);
		// 34 (100010)
		task.checkEvenOdd(34);
		// -12 (∞11110100)
		task.checkEvenOdd(-12);
		// 7 (111)
		task.checkEvenOdd(7);
		// 21 (00010101)
		task.checkEvenOdd(21);
		// -11 (11110101)
		task.checkEvenOdd(-11);
	}
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
/*
  Swift 4 Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	// Determine whether given number is Even or Odd
	func checkEvenOdd(_ num: Int)
	{
		// Display given number
		print("\n Number : ", num, terminator: "");
		if (num % 2 == 0)
		{
			// When last bit is not set
			print("\n Is Even Number ");
		}
		else
		{
			print("\n Is Odd Number");
		}
	}
}
func main()
{
	let task: Comparison = Comparison();
	// Test Cases
	// 12 (1100)
	task.checkEvenOdd(12);
	// 34 (100010)
	task.checkEvenOdd(34);
	// -12 (∞11110100)
	task.checkEvenOdd(-12);
	// 7 (111)
	task.checkEvenOdd(7);
	// 21 (00010101)
	task.checkEvenOdd(21);
	// -11 (11110101)
	task.checkEvenOdd(-11);
}
main();

Output

 Number :  12
 Is Even Number

 Number :  34
 Is Even Number

 Number :  -12
 Is Even Number

 Number :  7
 Is Odd Number

 Number :  21
 Is Odd Number

 Number :  -11
 Is Odd Number
/*
  Kotlin Program 
  Check whether a given number is even or odd
*/
class Comparison
{
	// Determine whether given number is Even or Odd
	fun checkEvenOdd(num: Int): Unit
	{
		// Display given number
		print("\n Number : " + num);
		if (num % 2 == 0)
		{
			// When last bit is not set
			print("\n Is Even Number \n");
		}
		else
		{
			print("\n Is Odd Number\n");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	var task: Comparison = Comparison();
	// Test Cases
	// 12 (1100)
	task.checkEvenOdd(12);
	// 34 (100010)
	task.checkEvenOdd(34);
	// -12 (∞11110100)
	task.checkEvenOdd(-12);
	// 7 (111)
	task.checkEvenOdd(7);
	// 21 (00010101)
	task.checkEvenOdd(21);
	// -11 (11110101)
	task.checkEvenOdd(-11);
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd Number
// Rust Program 
// Check whether a given number is even or odd
fn main()
{
	// Test Cases
	// 12 (1100)
	check_even_odd(12);
	// 34 (100010)
	check_even_odd(34);
	// -12 (∞11110100)
	check_even_odd(-12);
	// 7 (111)
	check_even_odd(7);
	// 21 (00010101)
	check_even_odd(21);
	// -11 (11110101)
	check_even_odd(-11);
}
fn check_even_odd(num: i32)
{
	// Display given number
	print!("\n Number : {}", num);
	if num % 2 == 0
	{
		// When last bit is not set
		print!("\n Is Even Number \n");
	}
	else
	{
		print!("\n Is Odd Number\n");
	}
}

Output

 Number : 12
 Is Even Number

 Number : 34
 Is Even Number

 Number : -12
 Is Even Number

 Number : 7
 Is Odd Number

 Number : 21
 Is Odd Number

 Number : -11
 Is Odd 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