Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that reads an integer (greater than 0) from the console and flips the digits of the number, using the arithmetic operators

Write a Python 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.



Step by Step Solution

3.56 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

Phyton num 45629383873883938 rev 0 def reverseNumberPrintEvenDigitsnumber count0 to count even digits in reverse number rev0 whilenumber 0 countcount1 a number 10 ifcount20 examplein reversed number1 digit is odd2nd is even3rd is odd and so on rev rev 10 a number number10 return rev printOrignal number isnum printReverse number only even digitsisreverseNumberPrintEvenDigitsnum ScreenShot C Language include include define N 200 here number can be in range 0 to 18446744073709551615 unsigned long long int reversNumberAndPrintEvenDigitsunsigned long long int num unsigned long long int revnum 0 int temp1 int count0 to count odd even digits whilenum 0 count tempnum10 ifcount20 revnum revnum10 temp num num10 return revnum If you wand number to be as long as you want use this here input can be as long as N defined void reversNumberPrintEven Entering number from input int numN char bufN int numberOfDigits1 printfEnter the number fgetsbuf sizeof buf stdin fgets puts terminating null char at the end forint i0iifbufi0 bufi numberOfDigitsi1 break numibufi 0 reversing the number printfReverse of number isonly even digits int count0 forint inumberOfDigitsi0i count ifcount20 to count odd even digit ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithms in Python

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

1st edition

1118290275, 1-118-54958-2, 978-1118290279

More Books

Students also viewed these Algorithms questions

Question

Draw the Fischer and Newman projection formulas for l-threose.

Answered: 1 week ago