Computer Science, asked by reenasing1976, 9 months ago

WAP to input a number and check weather it is a digital number or not​

Answers

Answered by Prathiksha1sweetie
0

Answer:

HEY MATE, HERE IS YOUR ANSWER :)

Explanation:

A) Java Program:-

class GFG

{

    static boolean isDigitPresent(int x, int d)

    {

        while (x > 0)

        {

            if (x % 10 == d)

                break;

  

            x = x / 10;

        }

        return (x > 0);

    }

    static void printNumbers(int n, int d)

    {

        for (int i = 0; i <= n;i++)

            if (i == d || isDigitPresent(i, d))

                System.out.print(i + " ");

    }

  

    public static void main(String[] args)

    {

        int n = 47, d = 7;

        printNumbers(n, d);

    }

}

B) C++

// Returns true if d is present as digit

// in number x.

bool isDigitPresent(int x, int d)

{

    // Breal loop if d is present as digit

    while (x > 0)

    {

        if (x % 10 == d)

            break;

  

        x = x / 10;

    }

  

    // If loop broke

    return (x > 0);

}

  

// function to display the values

void printNumbers(int n, int d)

{

    // Check all numbers one by one

    for (int i = 0; i <= n; i++)

  

        // checking for digit

        if (i == d || isDigitPresent(i, d))

            cout << i << " ";

}

  

// Driver code

int main()

{

    int n = 47, d = 7;

    printNumbers(n, d);

    return 0;

}

MARK AS BRAINIEST :)

Similar questions