Ask Question
20 July, 22:11

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. 21 July, 01:04
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers