# Check if a number is a mystery number

Here given code implementation process.

``````// C program
// Check if a number is a mystery number

#include <stdio.h>

int reverse_num(int number)
{
int result = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = number / 10;
}
//returning the reversal of number
return result;
}

//Check whether given number is Mystery Number or not
void is_mystery_no(int number)
{
int status = 0;
int x = 1;
int y = 0;
int counter = 1;
while (counter <= (number / 2) && status == 0)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (reverse_num(x) == y)
{
//When both numbers are equal
status = 1;
}
}
counter++;
}
if (status == 1)
{
printf("\n [%d] Is Mystery Number Of (%d,%d)", number, x, y);
}
else
{
printf("\n [%d] Is Not Mystery Number", number);
}
}

int main()
{
//Test case
is_mystery_no(33);
is_mystery_no(948);
is_mystery_no(44);
is_mystery_no(123);
is_mystery_no(143);
is_mystery_no(154);
return 0;
}``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````// Java program
// Check if a number is a mystery number

class MysteryNo
{
public int reverse_num(int number)
{
int result = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = number / 10;
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
public void is_mystery_no(int number)
{
boolean status = false;
int x = 1;
int y = 0;
int counter = 1;
while (counter <= (number / 2) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter++;
}
if (status == true)
{
System.out.print("\n [" + number + "] Is Mystery Number Of (" + x + "," + y + ")");
}
else
{
System.out.print("\n [" + number + "] Is Not Mystery Number");
}
}
public static void main(String[] args)
{
MysteryNo obj = new MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
}
}``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````//Include header file
#include <iostream>
using namespace std;

// C++ program
// Check if a number is a mystery number

class MysteryNo
{
public: int reverse_num(int number)
{
int result = 0;
while (number != 0)
{
result = result *10 + (number % 10);
number = number / 10;
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
void is_mystery_no(int number)
{
bool status = false;
int x = 1;
int y = 0;
int counter = 1;
while (counter <= (number / 2) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (this->reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter++;
}
if (status == true)
{
cout << "\n [" << number << "] Is Mystery Number Of (" << x << "," << y << ")";
}
else
{
cout << "\n [" << number << "] Is Not Mystery Number";
}
}
};
int main()
{
MysteryNo obj = MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
return 0;
}``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````//Include namespace system
using System;

// C# program
// Check if a number is a mystery number

class MysteryNo
{
public int reverse_num(int number)
{
int result = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = number / 10;
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
public void is_mystery_no(int number)
{
Boolean status = false;
int x = 1;
int y = 0;
int counter = 1;
while (counter <= (number / 2) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter++;
}
if (status == true)
{
Console.Write("\n [" + number + "] Is Mystery Number Of (" + x + "," + y + ")");
}
else
{
Console.Write("\n [" + number + "] Is Not Mystery Number");
}
}
public static void Main(String[] args)
{
MysteryNo obj = new MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
}
}``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````<?php
// Php program
// Check if a number is a mystery number
class MysteryNo
{
public	function reverse_num(\$number)
{
\$result = 0;
while (\$number != 0)
{
\$result = \$result * 10 + (\$number % 10);
\$number = intval(\$number / 10);
}
//returning the reversal of number
return \$result;
}
//Check whether given number is Mystery Number or not
public	function is_mystery_no(\$number)
{
\$status = false;
\$x = 1;
\$y = 0;
\$counter = 1;
while (\$counter <= (intval(\$number / 2)) && \$status == false)
{
\$x = \$counter;
\$y = \$number - \$counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (\$x % 10 != 0 && \$y % 10 != 0)
{
if (\$this->reverse_num(\$x) == \$y)
{
//When both numbers are equal
\$status = true;
}
}
\$counter++;
}
if (\$status == true)
{
echo "\n [". \$number ."] Is Mystery Number Of (". \$x .",". \$y .")";
}
else
{
echo "\n [". \$number ."] Is Not Mystery Number";
}
}
}

function main()
{
\$obj = new MysteryNo();
//Test case
\$obj->is_mystery_no(33);
\$obj->is_mystery_no(948);
\$obj->is_mystery_no(44);
\$obj->is_mystery_no(123);
\$obj->is_mystery_no(143);
\$obj->is_mystery_no(154);
}
main();``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````// Node Js program
// Check if a number is a mystery number
class MysteryNo
{
reverse_num(number)
{
var result = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = parseInt(number / 10);
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
is_mystery_no(number)
{
var status = false;
var x = 1;
var y = 0;
var counter = 1;
while (counter <= (parseInt(number / 2)) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (this.reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter++;
}
if (status == true)
{
process.stdout.write("\n [" + number + "] Is Mystery Number Of (" + x + "," + y + ")");
}
else
{
process.stdout.write("\n [" + number + "] Is Not Mystery Number");
}
}
}

function main()
{
var obj = new MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
}
main();``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````#  Python 3 program
#  Check if a number is a mystery number

class MysteryNo :
def reverse_num(self, number) :
result = 0
while (number != 0) :
result = result * 10 + (number % 10)
number = int(number / 10)

# returning the reversal of number
return result

# Check whether given number is Mystery Number or not
def is_mystery_no(self, number) :
status = False
x = 1
y = 0
counter = 1
while (counter <= (int(number / 2)) and status == False) :
x = counter
y = number - counter
#  Note that x + y is always equal to given number
#  Check whether, given number are last digit is zero or not
if (x % 10 != 0 and y % 10 != 0) :
if (self.reverse_num(x) == y) :
# When both numbers are equal
status = True

counter += 1

if (status == True) :
print("\n [", number ,"] Is Mystery Number Of (", x ,",", y ,")", end = "")
else :
print("\n [", number ,"] Is Not Mystery Number", end = "")

def main() :
obj = MysteryNo()
# Test case
obj.is_mystery_no(33)
obj.is_mystery_no(948)
obj.is_mystery_no(44)
obj.is_mystery_no(123)
obj.is_mystery_no(143)
obj.is_mystery_no(154)

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

#### Output

`````` [ 33 ] Is Mystery Number Of ( 12 , 21 )
[ 948 ] Is Mystery Number Of ( 177 , 771 )
[ 44 ] Is Mystery Number Of ( 13 , 31 )
[ 123 ] Is Not Mystery Number
[ 143 ] Is Mystery Number Of ( 49 , 94 )
[ 154 ] Is Mystery Number Of ( 59 , 95 )``````
``````#  Ruby program
#  Check if a number is a mystery number

class MysteryNo
def reverse_num(number)
result = 0
while (number != 0)
result = result * 10 + (number % 10)
number = number / 10
end

# returning the reversal of number
return result
end

# Check whether given number is Mystery Number or not
def is_mystery_no(number)
status = false
x = 1
y = 0
counter = 1
while (counter <= (number / 2) && status == false)
x = counter
y = number - counter
#  Note that x + y is always equal to given number
#  Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
if (self.reverse_num(x) == y)
# When both numbers are equal
status = true
end

end

counter += 1
end

if (status == true)
print("\n [", number ,"] Is Mystery Number Of (", x ,",", y ,")")
else
print("\n [", number ,"] Is Not Mystery Number")
end

end

end

def main()
obj = MysteryNo.new()
# Test case
obj.is_mystery_no(33)
obj.is_mystery_no(948)
obj.is_mystery_no(44)
obj.is_mystery_no(123)
obj.is_mystery_no(143)
obj.is_mystery_no(154)
end

main()``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````// Scala program
// Check if a number is a mystery number

class MysteryNo
{
def reverse_num(n: Int): Int = {
var number: Int = n;
var result: Int = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = (number / 10).toInt;
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
def is_mystery_no(number: Int): Unit = {
var status: Boolean = false;
var x: Int = 1;
var y: Int = 0;
var counter: Int = 1;
while (counter <= ((number / 2).toInt) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter += 1;
}
if (status == true)
{
print("\n [" + number + "] Is Mystery Number Of (" + x + "," + y + ")");
}
else
{
print("\n [" + number + "] Is Not Mystery Number");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MysteryNo = new MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
}
}``````

#### Output

`````` [33] Is Mystery Number Of (12,21)
[948] Is Mystery Number Of (177,771)
[44] Is Mystery Number Of (13,31)
[123] Is Not Mystery Number
[143] Is Mystery Number Of (49,94)
[154] Is Mystery Number Of (59,95)``````
``````// Swift 4 program
// Check if a number is a mystery number
class MysteryNo
{
func reverse_num(_ n: Int) -> Int
{
var number: Int = n;
var result: Int = 0;
while (number != 0)
{
result = result * 10 + (number % 10);
number = number / 10;
}
//returning the reversal of number
return result;
}
//Check whether given number is Mystery Number or not
func is_mystery_no(_ number: Int)
{
var status: Bool = false;
var x: Int = 1;
var y: Int = 0;
var counter: Int = 1;
while (counter <= (number / 2) && status == false)
{
x = counter;
y = number - counter;
// Note that x + y is always equal to given number
// Check whether, given number are last digit is zero or not
if (x % 10 != 0 && y % 10 != 0)
{
if (self.reverse_num(x) == y)
{
//When both numbers are equal
status = true;
}
}
counter += 1;
}
if (status == true)
{
print("\n [", number ,"]Is Mystery Number Of (", x ,",", y ,")", terminator: "");
}
else
{
print("\n [", number ,"]Is Not Mystery Number", terminator: "");
}
}
}
func main()
{
let obj: MysteryNo = MysteryNo();
//Test case
obj.is_mystery_no(33);
obj.is_mystery_no(948);
obj.is_mystery_no(44);
obj.is_mystery_no(123);
obj.is_mystery_no(143);
obj.is_mystery_no(154);
}
main();``````

#### Output

`````` [ 33 ]Is Mystery Number Of ( 12 , 21 )
[ 948 ]Is Mystery Number Of ( 177 , 771 )
[ 44 ]Is Mystery Number Of ( 13 , 31 )
[ 123 ]Is Not Mystery Number
[ 143 ]Is Mystery Number Of ( 49 , 94 )
[ 154 ]Is Mystery Number Of ( 59 , 95 )``````

## 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.

### New Comment

© 2022, kalkicode.com, All rights reserved