Ask Question
11 August, 16:09

Write a program that reads an integer (greater than 0) from the console and flips the digits of the number, using the arithmetic operators / / and %, while only printing out the even digits in the flipped order. Make sure that your program works for any number of digits and that the output does not have a newline character at the end.

+5
Answers (1)
  1. 11 August, 18:22
    0
    const stdin = process. openStdin ();

    const stdout = process. stdout;

    const reverse = input = > { / /checks if input is number

    if (isNaN (parseInt (input))) {

    stdout. write ("Input is not a number");

    }

    if (parseInt (input) < = 0) {. / / checks if no. is positive

    stdout. write ("Input is not a positive number");

    }

    let arr = []; / / pushing no. in array

    input. split (""). map (number = > {

    if (number % 2 = = 0) {

    arr. push (number);

    }

    });

    console. log (arr. reverse (). join ("")); / / reversing the array

    };

    stdout. write ("Enter a number: ");

    let input = null;

    stdin. addListener ("data", text = > {

    reverse (text. toString (). trim ()); / /reversing

    stdin. pause ();

    });

    Explanation:

    In this program, we are taking input from the user and checking if it is a number and if it is positive. We will only push even numbers in the array and then reversing the array and showing it on the console.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that reads an integer (greater than 0) from the console and flips the digits of the number, using the arithmetic operators ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers