Question

the user should be prompted to enter an integer and then your program will produce another...

the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit in the integer... Result: 24 Would you like to enter another integer (y/n): y Enter an integer: 455 Number is odd, taking every third digit in the integer... Result: 5 Would you like to enter another integer (y/n): y Enter an integer: 1245 Number is odd, taking every third digit in the integer... Result: 15 Would you like to enter another integer (y/n): y Enter an integer: 12356 Number is even, taking every other digit in the integer... Result: 136 Would you like to enter another integer (y/n): n When the entered number is even, you take (or keep) every other digit in the integer, below are a few examples: Value Result 0 0 1358 38 247380726 27876 When the entered number is odd, you take (or keep) every third digit in the integer, below are a few examples: Value Result 1 1 123 3 9540923 903 CS1044 Summer 2016 You may assume that all of the integers entered (odd or even) will be >= 0. Also notice that your program should ask whether another integer should be entered. If the response to the prompt is "y" your program should ask for another integer and perform the appropriate computations, if the user inputs an "n" the program should end. At this point you don't have to worry about incorrect input, when asked "Would you like to enter another integer (y/n): ", the input will always be a "y" or an "n" character. Your program should be able to handle an arbitrary number of integers. In the example above there were only 4 integers processed, but you should be able to handle 10, 20, 50, or more different integers during the course of running your program without issue. The Mod (%) Operator The mod operator produces the remainder of an integer division, so 0 % 2 = 0, 1 % 2 = 1, 2 % 2 = 0, and 3 % 2 = 1. One common use of the mod operator is determining whether a number is even or odd. If you mod with 2 and the result is 0, the number is even; if the result is 1, the number is odd: 1234 % 2 = 0 // Zero remainder, even. 123 % 2 = 1 // Non-zero remainder, not even. Further, let's say I want to get each of the digits in the integer in 1234, I can do that with the mod operator and integer division: // Get the least significant digit. 1234 % 10 = 4 // Shave off one digit using division. 1234 / 10 = 123 // Get the next least significant digit. 123 % 10 = 3 // Shave off one digit using division. 123 / 10 = 12 // Get the next least significant digit. 12 % 10 = 2 // Shave off one digit using division. 12 / 10 = 1 // Get the next least significant digit. 1 % 10 = 1 // Shave off one digit using division. 1 / 10 = 0

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
the user should be prompted to enter an integer and then your program will produce another...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • P.2. Division Write a C program to input an integer n. Then the program asks users...

    P.2. Division Write a C program to input an integer n. Then the program asks users to input n integers. Calculate the sum of all non negative integers and the division of this with every negative integer in the sequence. p3 Write a C program to print all 3-digit abc numbers, satisfying: (a+b+c)=(a.b.c). Example: 3-digit 123 number fulfills requirement as (1+2+3)=1.2.3

  • Problem 1 Write a Python program to do the following: (A) Ask the user to enter...

    Problem 1 Write a Python program to do the following: (A) Ask the user to enter as many integers from 1 to 10 as he/she wants. Store the integers entered by the user in a list. Every time after the user has entered an integer, use a yes/no type question to ask whether he/she wants to enter another one. (B) Display the list. (C) Calculate and display the average of the integers in the list. (D) If the average is...

  • Exercise 9.2 Write a Python program that collects from the user a single integer. Have the...

    Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...

  • Write a C program to do the following 1) request user to enter 10 integer into...

    Write a C program to do the following 1) request user to enter 10 integer into an array 2) sort the array in ascending order 3) display the sorted array 4) count the number of odd and even number in the array and print out the result 5) add the value of the odd number and even number and calculate the average of the odd and even number. display the result 6) write function addNumber() to add all the number...

  • NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number...

    NASM ASSEMBLY WINDOWS DOSBOX: 5) Write assembly program that asks the user to enter a number ( the user should input any integer number, say N), then the program outputs N if N is even; or N+3 if N is odd ( note: the output is always even) Example: Enter any number: 25 Even output is: 28 Another example: Enter any number: 32 Even output is: 32.

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • Write a program that prompts the user for positive integers, only stopping when a negative integer...

    Write a program that prompts the user for positive integers, only stopping when a negative integer or zero is given. The program should then print out how many of the positive integers were odd. Example: Enter a positive integer (0 or negative to stop): 9 Enter a positive integer (0 or negative to stop): 4 Enter a positive integer (0 or negative to stop): 7 Enter a positive integer (0 or negative to stop): -3 You entered 2 odd integers....

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement...

    Please use Python Exercise 1 Create a program named sentinel_loop using break. This program should implement functionality that is the same as the Part 1 tutorial example, except for the following differences: • • This program should count even and odd integers. This program should report counts of even and odd integers. Remember that even integers can be identified using the test condition: value % 2 == 0 Remember to test your code for appropriate behavior when the user signals...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT