Odious number

Here given code implementation process.

// C Program
// Odious number
#include <stdio.h>

void isOdiousNo(int num)
{
	// Test case 
	// ➀ Number is positive
	// ➁ Odd number of 1s in its binary expansion
	// (Active bits (1s) Occurs Odd number)
	int result = 0;
	if (num > 0)
	{
		// Case 1 valid
		int n = num;
		int count = 0;
		while (n > 0)
		{
			if ((1 & n) == 1)
			{
				// Count active bits
				count++;
			}
			// Right shift
			n = n >> 1;
		}
		if (count % 2 != 0)
		{
			result = 1;
		}
	}
	if (result == 1)
	{
		printf("\n Number %d is Odious Number ", num);
	}
	else
	{
		printf("\n Number %d is not Odious Number ", num);
	}
}
int main()
{
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	isOdiousNo(9867);
	return 0;
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
/*
    Java Program
    Odious number
*/
public class Checker
{
	public void isOdiousNo(int num)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		int result = 0;
		if (num > 0)
		{
			// Case 1 valid
			int n = num;
			int count = 0;
			while (n > 0)
			{
				if ((1 & n) == 1)
				{
					// Count active bits
					count++;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			System.out.print("\n Number " + 
                             num + " is Odious Number ");
		}
		else
		{
			System.out.print("\n Number " + 
                             num + " is not Odious Number ");
		}
	}
	public static void main(String[] args)
	{
		Checker task = new Checker();
		// Test A
		// n = 2357
		// [100100110101] Binary
		// Active bits = 6 (1s)
		// Result : No
		task.isOdiousNo(2357);
		// Test B
		// n = 233
		// [11101001] Binary
		// Active bits = 5 (1s)
		// Result : Yes
		task.isOdiousNo(233);
		// Test C
		// n = 9867
		// [10011010001011] Binary
		// Active bits = 7 (1s)
		// Result : Yes
		task.isOdiousNo(9867);
	}
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
// Include header file
#include <iostream>
using namespace std;
/*
    C++ Program
    Odious number
*/
class Checker
{
	public: void isOdiousNo(int num)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		int result = 0;
		if (num > 0)
		{
			// Case 1 valid
			int n = num;
			int count = 0;
			while (n > 0)
			{
				if ((1 &n) == 1)
				{
					// Count active bits
					count++;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			cout << "\n Number " << num << " is Odious Number ";
		}
		else
		{
			cout << "\n Number " << num << " is not Odious Number ";
		}
	}
};
int main()
{
	Checker *task = new Checker();
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	task->isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	task->isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	task->isOdiousNo(9867);
	return 0;
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
// Include namespace system
using System;
/*
    Csharp Program
    Odious number
*/
public class Checker
{
	public void isOdiousNo(int num)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		int result = 0;
		if (num > 0)
		{
			// Case 1 valid
			int n = num;
			int count = 0;
			while (n > 0)
			{
				if ((1 & n) == 1)
				{
					// Count active bits
					count++;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			Console.Write("\n Number " + num + " is Odious Number ");
		}
		else
		{
			Console.Write("\n Number " + num + " is not Odious Number ");
		}
	}
	public static void Main(String[] args)
	{
		Checker task = new Checker();
		// Test A
		// n = 2357
		// [100100110101] Binary
		// Active bits = 6 (1s)
		// Result : No
		task.isOdiousNo(2357);
		// Test B
		// n = 233
		// [11101001] Binary
		// Active bits = 5 (1s)
		// Result : Yes
		task.isOdiousNo(233);
		// Test C
		// n = 9867
		// [10011010001011] Binary
		// Active bits = 7 (1s)
		// Result : Yes
		task.isOdiousNo(9867);
	}
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
package main
import "fmt"
/*
    Go Program
    Odious number
*/

func isOdiousNo(num int) {
	// Test case 
	// ➀ Number is positive
	// ➁ Odd number of 1s in its binary expansion
	// (Active bits (1s) Occurs Odd number)
	var result int = 0
	if num > 0 {
		// Case 1 valid
		var n int = num
		var count int = 0
		for (n > 0) {
			if (1 & n) == 1 {
				// Count active bits
				count++
			}
			// Right shift
			n = n >> 1
		}
		if count % 2 != 0 {
			result = 1
		}
	}
	if result == 1 {
		fmt.Print("\n Number ", num, " is Odious Number ")
	} else {
		fmt.Print("\n Number ", num, " is not Odious Number ")
	}
}
func main() {
	
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	isOdiousNo(2357)
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	isOdiousNo(233)
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	isOdiousNo(9867)
}

Output

 Number  2357  is not Odious Number
 Number  233  is Odious Number
 Number  9867  is Odious Number
<?php
/*
    Php Program
    Odious number
*/
class Checker
{
	public	function isOdiousNo($num)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		$result = 0;
		if ($num > 0)
		{
			// Case 1 valid
			$n = $num;
			$count = 0;
			while ($n > 0)
			{
				if ((1 & $n) == 1)
				{
					// Count active bits
					$count++;
				}
				// Right shift
				$n = $n >> 1;
			}
			if ($count % 2 != 0)
			{
				$result = 1;
			}
		}
		if ($result == 1)
		{
			echo("\n Number ".$num.
				" is Odious Number ");
		}
		else
		{
			echo("\n Number ".$num.
				" is not Odious Number ");
		}
	}
}

function main()
{
	$task = new Checker();
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	$task->isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	$task->isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	$task->isOdiousNo(9867);
}
main();

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
/*
    Node JS Program
    Odious number
*/
class Checker
{
	isOdiousNo(num)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		var result = 0;
		if (num > 0)
		{
			// Case 1 valid
			var n = num;
			var count = 0;
			while (n > 0)
			{
				if ((1 & n) == 1)
				{
					// Count active bits
					count++;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			process.stdout.write("\n Number " + 
                                 num + " is Odious Number ");
		}
		else
		{
			process.stdout.write("\n Number " + 
                                 num + " is not Odious Number ");
		}
	}
}

function main()
{
	var task = new Checker();
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	task.isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	task.isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	task.isOdiousNo(9867);
}
main();

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
#    Python 3 Program
#    Odious number
class Checker :
	def isOdiousNo(self, num) :
		#  Test case 
		#  ➀ Number is positive
		#  ➁ Odd number of 1s in its binary expansion
		#  (Active bits (1s) Occurs Odd number)
		result = 0
		if (num > 0) :
			#  Case 1 valid
			n = num
			count = 0
			while (n > 0) :
				if ((1 & n) == 1) :
					#  Count active bits
					count += 1
				
				#  Right shift
				n = n >> 1
			
			if (count % 2 != 0) :
				result = 1
			
		
		if (result == 1) :
			print("\n Number ", num ,
                  " is Odious Number ", end = "", sep = "")
		else :
			print("\n Number ", num ,
                  " is not Odious Number ", end = "", sep = "")
		
	

def main() :
	task = Checker()
	#  Test A
	#  n = 2357
	#  [100100110101] Binary
	#  Active bits = 6 (1s)
	#  Result : No
	task.isOdiousNo(2357)
	#  Test B
	#  n = 233
	#  [11101001] Binary
	#  Active bits = 5 (1s)
	#  Result : Yes
	task.isOdiousNo(233)
	#  Test C
	#  n = 9867
	#  [10011010001011] Binary
	#  Active bits = 7 (1s)
	#  Result : Yes
	task.isOdiousNo(9867)

if __name__ == "__main__": main()

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
#    Ruby Program
#    Odious number
class Checker 
	def isOdiousNo(num) 
		#  Test case 
		#  ➀ Number is positive
		#  ➁ Odd number of 1s in its binary expansion
		#  (Active bits (1s) Occurs Odd number)
		result = 0
		if (num > 0) 
			#  Case 1 valid
			n = num
			count = 0
			while (n > 0) 
				if ((1 & n) == 1) 
					#  Count active bits
					count += 1
				end

				#  Right shift
				n = n >> 1
			end

			if (count % 2 != 0) 
				result = 1
			end

		end

		if (result == 1) 
			print("\n Number ", num ," is Odious Number ")
		else
 
			print("\n Number ", num ," is not Odious Number ")
		end

	end

end

def main() 
	task = Checker.new()
	#  Test A
	#  n = 2357
	#  [100100110101] Binary
	#  Active bits = 6 (1s)
	#  Result : No
	task.isOdiousNo(2357)
	#  Test B
	#  n = 233
	#  [11101001] Binary
	#  Active bits = 5 (1s)
	#  Result : Yes
	task.isOdiousNo(233)
	#  Test C
	#  n = 9867
	#  [10011010001011] Binary
	#  Active bits = 7 (1s)
	#  Result : Yes
	task.isOdiousNo(9867)
end

main()

Output

 Number 2357 is not Odious Number 
 Number 233 is Odious Number 
 Number 9867 is Odious Number 
/*
    Scala Program
    Odious number
*/
class Checker()
{
	def isOdiousNo(num: Int): Unit = {
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		var result: Int = 0;
		if (num > 0)
		{
			// Case 1 valid
			var n: Int = num;
			var count: Int = 0;
			while (n > 0)
			{
				if ((1 & n) == 1)
				{
					// Count active bits
					count += 1;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			print("\n Number " + num + " is Odious Number ");
		}
		else
		{
			print("\n Number " + num + " is not Odious Number ");
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Checker = new Checker();
		// Test A
		// n = 2357
		// [100100110101] Binary
		// Active bits = 6 (1s)
		// Result : No
		task.isOdiousNo(2357);
		// Test B
		// n = 233
		// [11101001] Binary
		// Active bits = 5 (1s)
		// Result : Yes
		task.isOdiousNo(233);
		// Test C
		// n = 9867
		// [10011010001011] Binary
		// Active bits = 7 (1s)
		// Result : Yes
		task.isOdiousNo(9867);
	}
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious Number
/*
    Swift 4 Program
    Odious number
*/
class Checker
{
	func isOdiousNo(_ num: Int)
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		var result: Int = 0;
		if (num > 0)
		{
			// Case 1 valid
			var n: Int = num;
			var count: Int = 0;
			while (n > 0)
			{
				if ((1 & n) == 1)
				{
					// Count active bits
					count += 1;
				}
				// Right shift
				n = n >> 1;
			}
			if (count % 2  != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			print("\n Number ", num ,
                  " is Odious Number ", terminator: "");
		}
		else
		{
			print("\n Number ", num ,
                  " is not Odious Number ", terminator: "");
		}
	}
}
func main()
{
	let task: Checker = Checker();
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	task.isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	task.isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	task.isOdiousNo(9867);
}
main();

Output

 Number  2357  is not Odious Number
 Number  233  is Odious Number
 Number  9867  is Odious Number
/*
    Kotlin Program
    Odious number
*/
class Checker
{
	fun isOdiousNo(num: Int): Unit
	{
		// Test case 
		// ➀ Number is positive
		// ➁ Odd number of 1s in its binary expansion
		// (Active bits (1s) Occurs Odd number)
		var result: Int = 0;
		if (num > 0)
		{
			// Case 1 valid
			var n: Int = num;
			var count: Int = 0;
			while (n > 0)
			{
				if ((1 and n) == 1)
				{
					// Count active bits
					count += 1;
				}
				// Right shift
				n = n shr 1;
			}
			if (count % 2 != 0)
			{
				result = 1;
			}
		}
		if (result == 1)
		{
			print("\n Number " + num + " is Odious Number ");
		}
		else
		{
			print("\n Number " + num + " is not Odious Number ");
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Checker = Checker();
	// Test A
	// n = 2357
	// [100100110101] Binary
	// Active bits = 6 (1s)
	// Result : No
	task.isOdiousNo(2357);
	// Test B
	// n = 233
	// [11101001] Binary
	// Active bits = 5 (1s)
	// Result : Yes
	task.isOdiousNo(233);
	// Test C
	// n = 9867
	// [10011010001011] Binary
	// Active bits = 7 (1s)
	// Result : Yes
	task.isOdiousNo(9867);
}

Output

 Number 2357 is not Odious Number
 Number 233 is Odious Number
 Number 9867 is Odious 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