# Check if a number is bleak

Here given code implementation process.

``````// C Program
// Check if a number is bleak
#include <stdio.h>

// Returns the number of all active bits in n
int countActiveBit(int n)
{
int num = n;
int count = 0;
// Count active bits
while (num > 0)
{
count++;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
void isBleak(int num)
{
for (int i = 1; i < num; ++i)
{
if ((countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
printf(" %d is not bleak number\n", num);
return;
}
}
printf(" %d Is an bleak number\n", num);
}
int main(int argc, char const *argv[])
{
// Test Cases
isBleak(13);
isBleak(27);
isBleak(39);
isBleak(14);
isBleak(21);
return 0;
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````/*
Java Program
Check if a number is bleak
*/
public class BleakNumber
{
// Returns the number of all active bits in n
public int countActiveBit(int n)
{
int num = n;
int count = 0;
// Count active bits
while (num > 0)
{
count++;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
public void isBleak(int num)
{
for (int i = 1; i < num; ++i)
{
if ((countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
System.out.print(" " + num + " is not bleak number\n");
return;
}
}
System.out.print(" " + num + " Is an bleak number\n");
}
public static void main(String[] args)
{
// Test Cases
}
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````// Include header file
#include <iostream>
using namespace std;

/*
C++ Program
Check if a number is bleak
*/

class BleakNumber
{
public:
// Returns the number of all active bits in n
int countActiveBit(int n)
{
int num = n;
int count = 0;
// Count active bits
while (num > 0)
{
count++;
num = num &(num - 1);
}
return count;
}
// Determine that given number is bleak number or not
void isBleak(int num)
{
for (int i = 1; i < num; ++i)
{
if ((this->countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
cout << " " << num << " is not bleak number\n";
return;
}
}
cout << " " << num << " Is an bleak number\n";
}
};
int main()
{
// Test Cases
return 0;
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````// Include namespace system
using System;
/*
C# Program
Check if a number is bleak
*/
public class BleakNumber
{
// Returns the number of all active bits in n
public int countActiveBit(int n)
{
int num = n;
int count = 0;
// Count active bits
while (num > 0)
{
count++;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
public void isBleak(int num)
{
for (int i = 1; i < num; ++i)
{
if ((countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
Console.Write(" " + num + " is not bleak number\n");
return;
}
}
Console.Write(" " + num + " Is an bleak number\n");
}
public static void Main(String[] args)
{
// Test Cases
}
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````<?php
/*
Php Program
Check if a number is bleak
*/
class BleakNumber
{
// Returns the number of all active bits in n
public	function countActiveBit(\$n)
{
\$num = \$n;
\$count = 0;
// Count active bits
while (\$num > 0)
{
\$count++;
\$num = \$num & (\$num - 1);
}
return \$count;
}
// Determine that given number is bleak number or not
public	function isBleak(\$num)
{
for (\$i = 1; \$i < \$num; ++\$i)
{
if ((\$this->countActiveBit(\$i) + \$i) == \$num)
{
// When [i] and sum of active bits is equal to given number
echo " ". \$num ." is not bleak number\n";
return;
}
}
echo " ". \$num ." Is an bleak number\n";
}
}

function main()
{
// Test Cases
}
main();``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````/*
Node Js Program
Check if a number is bleak
*/
class BleakNumber
{
// Returns the number of all active bits in n
countActiveBit(n)
{
var num = n;
var count = 0;
// Count active bits
while (num > 0)
{
count++;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
isBleak(num)
{
for (var i = 1; i < num; ++i)
{
if ((this.countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
process.stdout.write(" " + num + " is not bleak number\n");
return;
}
}
process.stdout.write(" " + num + " Is an bleak number\n");
}
}

function main()
{
// Test Cases
}
main();``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````#   Python 3 Program
#   Check if a number is bleak

class BleakNumber :
#  Returns the number of all active bits in n
def countActiveBit(self, n) :
num = n
count = 0
#  Count active bits
while (num > 0) :
count += 1
num = num & (num - 1)

return count

#  Determine that given number is bleak number or not
def isBleak(self, num) :
i = 1
while (i < num) :
if ((self.countActiveBit(i) + i) == num) :
#  When [i] and sum of active bits is equal to given number
print(" ", num ," is not bleak number")
return

i += 1

print(" ", num ," Is an bleak number")

def main() :
#  Test Cases

if __name__ == "__main__": main()``````

#### Output

``````  13  Is an bleak number
27  is not bleak number
39  Is an bleak number
14  is not bleak number
21  Is an bleak number``````
``````#   Ruby Program
#   Check if a number is bleak

class BleakNumber
#  Returns the number of all active bits in n
def countActiveBit(n)
num = n
count = 0
#  Count active bits
while (num > 0)
count += 1
num = num & (num - 1)
end

return count
end

#  Determine that given number is bleak number or not
def isBleak(num)
i = 1
while (i < num)
if ((self.countActiveBit(i) + i) == num)
#  When [i] and sum of active bits is equal to given number
print(" ", num ," is not bleak number\n")
return
end

i += 1
end

print(" ", num ," Is an bleak number\n")
end

end

def main()
#  Test Cases
end

main()``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number
``````
``````/*
Scala Program
Check if a number is bleak
*/
class BleakNumber
{
// Returns the number of all active bits in n
def countActiveBit(n: Int): Int = {
var num: Int = n;
var count: Int = 0;
// Count active bits
while (num > 0)
{
count += 1;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
def isBleak(num: Int): Unit = {
var i: Int = 1;
while (i < num)
{
if ((this.countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
print(" " + num + " is not bleak number\n");
return;
}
i += 1;
}
print(" " + num + " Is an bleak number\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: BleakNumber = new BleakNumber();
// Test Cases
}
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````/*
Swift 4 Program
Check if a number is bleak
*/
class BleakNumber
{
// Returns the number of all active bits in n
func countActiveBit(_ n: Int)->Int
{
var num: Int = n;
var count: Int = 0;
// Count active bits
while (num > 0)
{
count += 1;
num = num & (num - 1);
}
return count;
}
// Determine that given number is bleak number or not
func isBleak(_ num: Int)
{
var i: Int = 1;
while (i < num)
{
if ((self.countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
print(" ", num ," is not bleak number");
return;
}
i += 1;
}
print(" ", num ," Is an bleak number");
}
}
func main()
{
// Test Cases
}
main();``````

#### Output

``````  13  Is an bleak number
27  is not bleak number
39  Is an bleak number
14  is not bleak number
21  Is an bleak number``````
``````/*
Kotlin Program
Check if a number is bleak
*/
class BleakNumber
{
// Returns the number of all active bits in n
fun countActiveBit(n: Int): Int
{
var num: Int = n;
var count: Int = 0;
// Count active bits
while (num > 0)
{
count += 1;
num = num and(num - 1);
}
return count;
}
// Determine that given number is bleak number or not
fun isBleak(num: Int): Unit
{
var i: Int = 1;
while (i < num)
{
if ((this.countActiveBit(i) + i) == num)
{
// When [i] and sum of active bits is equal to given number
print(" " + num + " is not bleak number\n");
return;
}
i += 1;
}
print(" " + num + " Is an bleak number\n");
}
}
fun main(args: Array < String > ): Unit
{
// Test Cases
}``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````
``````// Rust Program
// Check if a number is bleak
fn main()
{
// Test Cases
is_bleak(13);
is_bleak(27);
is_bleak(39);
is_bleak(14);
is_bleak(21);
}
fn is_bleak(num: i32)
{
let mut i: i32 = 1;
while i < num
{
if (count_active_bit(i) + i) == num
{
// When [i] and sum of active bits is equal to given number
print!(" {} is not bleak number\n", num);
return;
}
i += 1;
}
print!(" {} Is an bleak number\n", num);
}
fn count_active_bit(n: i32)->i32
{
let mut num: i32 = n;
let mut count: i32 = 0;
// Count active bits
while num > 0
{
count = count + 1;
num = num & (num - 1);
}
return count;
} ``````

#### Output

`````` 13 Is an bleak number
27 is not bleak number
39 Is an bleak number
14 is not bleak number
21 Is an bleak number``````

## Comment

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.