Sunday, October 12, 2025
HomeData Modelling & AICheck whether a given number N is a Nude Number or not

Check whether a given number N is a Nude Number or not

Given an integer N, the task is to check whether N is a Nude number or not.
 

A Nude number is a number that is divisible by all of its digits (which should be nonzero). 
 

Example: 

Input: N = 672 
Output: Yes 
Explanation: 
Since, 672 is divisible by all of its three digits 6, 7 and 2. Therefore the output is Yes.

Input: N = 450 
Output: No 
Explanation: 
Since, 450 is not divisible by 0 (Also it gives exception). Therefore the output is No. 

 

Approach: Extract digits from number one by one and check these two conditions: 
 

  1. The digit must be non-zero, to avoid exception
  2. And the digit must divide the number N

When both these condition is satisfied by all digits of N, then the number is called Nude number.
Below is the implementation of the above approach:
 

C++




// C++ program to check if the
// number if Nude number or not
 
#include <iostream>
using namespace std;
 
// Check if all digits
// of num divide num
bool checkDivisbility(int num)
{
    // array to store all digits
    // of the given number
    int digit;
    int N = num;
    while (num != 0) {
        digit = num % 10;
        num = num / 10;
 
        // If any of the condition
        // is true for any digit
        // Then N is not a nude number
        if (digit == 0 || N % digit != 0)
            return false;
    }
 
    return true;
}
 
// Driver code
int main()
{
    int N = 128;
 
    bool result = checkDivisbility(N);
    if (result)
        cout << "Yes";
    else
        cout << "No";
 
    return 0;
}


Java




// Java program to check if the
// number if Nude number or not
import java.util.*;
class GFG{
 
// Check if all digits
// of num divide num
static boolean checkDivisbility(int num)
{
    // array to store all digits
    // of the given number
    int digit;
    int N = num;
    while (num != 0)
    {
        digit = num % 10;
        num = num / 10;
 
        // If any of the condition
        // is true for any digit
        // Then N is not a nude number
        if (digit == 0 || N % digit != 0)
            return false;
    }
    return true;
}
 
// Driver code
public static void main(String[] args)
{
    int N = 128;
 
    boolean result = checkDivisbility(N);
    if (result)
        System.out.print("Yes");
    else
        System.out.print("No");
}
}
 
// This code is contributed by 29AjayKumar


Python3




# Python3 program to check if the
# number if nude number or not
 
# Check if all digits
# of num divide num
def checkDivisbility(num):
     
    # Array to store all digits
    # of the given number
    digit = 0
    N = num
     
    while (num != 0):
        digit = num % 10
        num = num // 10
 
        # If any of the condition
        # is true for any digit
        # then N is not a nude number
        if (digit == 0 or N % digit != 0):
            return False
 
    return True
 
# Driver code
if __name__ == '__main__':
     
    N = 128
 
    result = checkDivisbility(N)
    if (result):
        print("Yes")
    else:
        print("No")
 
# This code is contributed by mohit kumar 29


C#




// C# program to check if the
// number if Nude number or not
using System;
class GFG{
 
// Check if all digits
// of num divide num
static bool checkDivisbility(int num)
{
    // array to store all digits
    // of the given number
    int digit;
    int N = num;
    while (num != 0)
    {
        digit = num % 10;
        num = num / 10;
 
        // If any of the condition
        // is true for any digit
        // Then N is not a nude number
        if (digit == 0 || N % digit != 0)
            return false;
    }
    return true;
}
 
// Driver code
public static void Main()
{
    int N = 128;
 
    bool result = checkDivisbility(N);
    if (result)
        Console.Write("Yes");
    else
        Console.Write("No");
}
}
 
// This code is contributed by Nidhi_biet


Javascript




<script>
 
// Javascript program to check if the
// number if Nude number or not
 
// Check if all digits
// of num divide num
function checkDivisbility(num)
{
    // array to store all digits
    // of the given number
    let digit;
    let N = num;
    while (num != 0) {
        digit = num % 10;
        num = Math.floor(num / 10);
 
        // If any of the condition
        // is true for any digit
        // Then N is not a nude number
        if (digit == 0 || N % digit != 0)
            return false;
    }
 
    return true;
}
 
// Driver code
  
    let N = 128;
 
    let result = checkDivisbility(N);
    if (result)
        document.write("Yes");
    else
        document.write("No");
 
// This code is contributed by Mayank Tyagi
 
</script>


Output: 

Yes

 

Time complexity: O( log10 N ), where N is the given integer.
Auxiliary space: O(1) as constant space is being used. 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32353 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6721 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11943 POSTS0 COMMENTS
Shaida Kate Naidoo
6841 POSTS0 COMMENTS
Ted Musemwa
7105 POSTS0 COMMENTS
Thapelo Manthata
6797 POSTS0 COMMENTS
Umr Jansen
6798 POSTS0 COMMENTS