Posted on by Kalkicode
Code Mathematics

# Check whether the given number is nude number or not

In this article, we will discuss the concept of nude numbers and how to determine whether a given number is a nude number or not. We will also provide a C program that implements the algorithm to check for nude numbers.

### Introduction

A nude number is a number that is divisible by each of its digits. In other words, if a number "N" is divisible by all its individual digits without any remainder, then it is considered a nude number. For example, the number 126 is a nude number because it is divisible by 1, 2, and 6. On the other hand, the number 361 is not a nude number because it is not divisible by 6.

### Problem Statement

The problem is to determine whether a given number is a nude number or not. Given an integer "N," we need to check if it is divisible by each of its digits.

### Example

Let's take a few examples to illustrate the concept:

• Number 126 is a nude number because it is divisible by 1, 2, and 6.
• Number 361 is not a nude number because it is not divisible by 6.
• Number 2120 is not a nude number because it is not divisible by 1.
• Number 48 is a nude number because it is divisible by 4 and 8.
• Number 1115 is a nude number because it is divisible by 1 and 5.

### Algorithm

Here is the algorithm to check whether a given number is a nude number:

1. Define a function named "isNudeNo" that takes an integer parameter "number."
2. Inside the function, initialize a variable "status" as 1. This variable will be used to indicate the result.
3. Initialize another variable "digit" as 0. This variable will be used to store the individual digits of the number.
4. Assign the value of "number" to a variable "n". This will be used for calculations without modifying the original number.
5. Using a loop, check if the number "n" is not equal to 0 and the "status" is still 1.
6. Inside the loop, calculate the last digit of "n" using the modulo operator and assign it to "digit".
7. Check if "digit" is equal to 0 or if the remainder of dividing "number" by "digit" is not equal to 0.
8. If either of the above conditions is true, set "status" to 0, indicating that the number is not a nude number.
9. Otherwise, divide "n" by 10 to remove the last digit and continue the loop.
10. After the loop, check the value of "status." If it is still 1, print that the number is a nude number. Otherwise, print that the number is not a nude number.

### Pseudocode

Here is the pseudocode representation of the algorithm:

``````
function isNudeNo(number):
status = 1
digit = 0
n = number
while n != 0 and status == 1:
digit = n % 10
if digit == 0 or (number % digit) != 0:
status = 0
else:
n = n / 10
if status == 1:
print "Number is a nude number"
else:
print "Number is not a nude number"```
```

## Code Solution

``````// C program for
// Check whether the given number is nude number or not
#include <stdio.h>

void isNudeNo(int number)
{
// Define some auxiliary variables
// result indicator
int status = 1;
// Use to store number digit
int digit = 0;
// Get given number
int n = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status == 1)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = 0;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status == 1)
{
printf(" Number %d is nude number\n", number);
}
else
{
printf(" Number %d is not nude number\n", number);
}
}
int main(int argc, char
const *argv[])
{
// Test Cases
isNudeNo(126);
isNudeNo(361);
isNudeNo(2120);
isNudeNo(48);
isNudeNo(1115);
return 0;
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````/*
Java Program for
Check whether the given number is nude number or not
*/
public class NudeNumber
{
public void isNudeNo(int number)
{
// Define some auxiliary variables
// result indicator
boolean status = true;
// Use to store number digit
int digit = 0;
// Get given number
int n = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status)
{
System.out.println(" Number " + number + " is nude number");
}
else
{
System.out.println(" Number " + number + " is not nude number");
}
}
public static void main(String[] args)
{
// Test Cases
}
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````// Include header file
#include <iostream>

using namespace std;
/*
C++ Program for
Check whether the given number is nude number or not
*/
class NudeNumber
{
public: void isNudeNo(int number)
{
// Define some auxiliary variables
// result indicator
bool status = true;
// Use to store number digit
int digit = 0;
// Get given number
int n = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status)
{
cout << " Number " << number << " is nude number" << endl;
}
else
{
cout << " Number " << number << " is not nude number" << endl;
}
}
};
int main()
{
// Test Cases
return 0;
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````// Include namespace system
using System;
/*
Csharp Program for
Check whether the given number is nude number or not
*/
public class NudeNumber
{
public void isNudeNo(int number)
{
// Define some auxiliary variables
// result indicator
Boolean status = true;
// Use to store number digit
int digit = 0;
// Get given number
int n = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status)
{
Console.WriteLine(" Number " + number + " is nude number");
}
else
{
Console.WriteLine(" Number " + number + " is not nude number");
}
}
public static void Main(String[] args)
{
// Test Cases
}
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````<?php
/*
Php Program for
Check whether the given number is nude number or not
*/
class NudeNumber
{
public	function isNudeNo(\$number)
{
// Define some auxiliary variables
// result indicator
\$status = true;
// Use to store number digit
\$digit = 0;
// Get given number
\$n = \$number;
// Check if number is divisible by each of its digits or not number
while (\$n != 0 && \$status)
{
// Get last digit of n
\$digit = \$n % 10;
// Check if digit is divisible by given number or not
if (\$digit == 0 || (\$number % \$digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
\$status = false;
}
else
{
// Remove last digit
\$n = (int)(\$n / 10);
}
}
if (\$status)
{
echo " Number ".\$number.
" is nude number".
"\n";
}
else
{
echo " Number ".\$number.
" is not nude number".
"\n";
}
}
}

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

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````/*
Node JS Program for
Check whether the given number is nude number or not
*/
class NudeNumber
{
isNudeNo(number)
{
// Define some auxiliary variables
// result indicator
var status = true;
// Use to store number digit
var digit = 0;
// Get given number
var n = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = parseInt(n / 10);
}
}
if (status)
{
console.log(" Number " + number + " is nude number");
}
else
{
console.log(" Number " + number + " is not nude number");
}
}
}

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

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````#  Python 3 Program for
#  Check whether the given number is nude number or not
class NudeNumber :
def isNudeNo(self, number) :
status = True
digit = 0
n = number
#  Check if number is divisible by each of its digits or not number
while (n != 0 and status) :
#  Get last digit of n
digit = n % 10
#  Check if digit is divisible by given number or not
if (digit == 0 or(number % digit) != 0) :
#  When number is not divisible by digit
#  Or digit is 0
status = False
else :
#  Remove last digit
n = int(n / 10)

if (status) :
print(" Number ", number ," is nude number")
else :
print(" Number ", number ," is not nude number")

def main() :
#  Test Cases

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

#### input

`````` Number  126  is nude number
Number  361  is not nude number
Number  2120  is not nude number
Number  48  is nude number
Number  1115  is nude number``````
``````#  Ruby Program for
#  Check whether the given number is nude number or not
class NudeNumber
def isNudeNo(number)
#  Define some auxiliary variables
#  result indicator
status = true
#  Use to store number digit
digit = 0
#  Get given number
n = number
#  Check if number is divisible by each of its digits or not number
while (n != 0 && status)
#  Get last digit of n
digit = n % 10
#  Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
#  When number is not divisible by digit
#  Or digit is 0
status = false
else
#  Remove last digit
n = n / 10
end

end

if (status)
print(" Number ", number ," is nude number", "\n")
else
print(" Number ", number ," is not nude number", "\n")
end

end

end

def main()
#  Test Cases
end

main()``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number
``````
``````/*
Scala Program for
Check whether the given number is nude number or not
*/
class NudeNumber()
{
def isNudeNo(number: Int): Unit = {
// Define some auxiliary variables
// result indicator
var status: Boolean = true;
// Use to store number digit
var digit: Int = 0;
// Get given number
var n: Int = number;
// Check if number is divisible by each of its digits or not number
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = (n / 10).toInt;
}
}
if (status)
{
println(" Number " + number + " is nude number");
}
else
{
println(" Number " + number + " is not nude number");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: NudeNumber = new NudeNumber();
// Test Cases
}
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````
``````/*
Swift 4 Program for
Check whether the given number is nude number or not
*/
class NudeNumber
{
func isNudeNo(_ number: Int)
{
// Define some auxiliary variables
// result indicator
var status: Bool = true;
// Use to store number digit
var digit: Int = 0;
// Get given number
var n: Int = number;
// Check if number is divisible by each of its digits or not number
while (n  != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit)  != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status)
{
print(" Number ", number ," is nude number");
}
else
{
print(" Number ", number ," is not nude number");
}
}
}
func main()
{
// Test Cases
}
main();``````

#### input

`````` Number  126  is nude number
Number  361  is not nude number
Number  2120  is not nude number
Number  48  is nude number
Number  1115  is nude number``````
``````/*
Kotlin Program for
Check whether the given number is nude number or not
*/
class NudeNumber
{
fun isNudeNo(number: Int): Unit
{
// Define some auxiliary variables
// result indicator
var status: Boolean = true;
// Use to store number digit
var digit: Int ;
// Get given number
var n: Int = number;
while (n != 0 && status)
{
// Get last digit of n
digit = n % 10;
// Check if digit is divisible by given number or not
if (digit == 0 || (number % digit) != 0)
{
// When number is not divisible by digit
// Or digit is 0
status = false;
}
else
{
// Remove last digit
n = n / 10;
}
}
if (status)
{
println(" Number " + number + " is nude number");
}
else
{
println(" Number " + number + " is not nude number");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test Cases
}``````

#### input

`````` Number 126 is nude number
Number 361 is not nude number
Number 2120 is not nude number
Number 48 is nude number
Number 1115 is nude number``````

### Explanation and Time Complexity

The given algorithm uses a loop to iterate through each digit of the number. The loop continues until there are no more digits left or until the "status" variable is set to 0.

The time complexity of the algorithm depends on the number of digits in the input number. Let's assume the number has "d" digits.

In the worst case scenario, the loop will iterate "d" times, performing constant time operations in each iteration. Therefore, the time complexity of the algorithm is O(d), where "d" represents the number of digits in the input number.

### Resultant Output Explanation

Let's analyze the output of the provided test cases:

• Number 126 is a nude number because it is divisible by 1, 2, and 6.
• Number 361 is not a nude number because it is not divisible by 6.
• Number 2120 is not a nude number because it is not divisible by 1.
• Number 48 is a nude number because it is divisible by 4 and 8.
• Number 1115 is a nude number because it is divisible by 1 and 5.

These results match the explanation provided earlier, confirming the correctness of the algorithm.

By implementing the provided C code and running it, you will obtain the same output for the test cases mentioned above.

### Finally

In this article, we explored the concept of nude numbers and discussed how to determine whether a given number is a nude number or not. We provided a detailed explanation of the problem, along with an algorithm and pseudocode to solve it. The time complexity of the algorithm was analyzed, and the resultant output was explained.

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

Categories
Relative Post