Question

Write a complete C++ program that do following. 1) Read a positive integer from the user...

Write a complete C++ program that do following.

1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0.

2) Create a size 10 array as counters for digits 0 - 9.

3) Use a while loop for processing

a) Single out the current last digit using modular 10 technique

b) Increment the corresponding counter through the index derived in a).

4) At the end display the non-zero counters and its corresponding digit in ascending order, i.e. 0 to 9.

For example, if the user enter 1773233, the output should be All digits occurrences:

1: 1

2: 1

3: 3

7: 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note:

Please find the below C++ program and sample output.

Please revert back in case of any concerns.

Program:


int main()
{
long int number;
int digits;
cout<<"Enter Number: ";
cin >> number;
int counter[10] ={0,0,0,0,0,0,0,0,0,0};
while (number != 0) {
digits = number % 10;
counter[digits] = counter[digits] + 1;
number = number/10;
}
for (int i=0;i<10;i++) {
if (counter[i] !=0) {
cout<<i<<": "<<counter[i]<<endl;
}
}
return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a complete C++ program that do following. 1) Read a positive integer from the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...

    Program : Write a complete C++ program that Input: Read a positive integer from the keyboard (user) with proper prompt text and save it to a variable. The integer have up to five digits. Processing: From the right most digit, extract every digit from the input integer using modular operator %then save the digit to a separate variable. Remove the right most digit from the integer using integer division operator /. Repeat above two steps till all digits have been...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Write a c++ program that reads numbers from the user, and prints a table showing how...

    Write a c++ program that reads numbers from the user, and prints a table showing how many times each digit appears in each number. The user should be able to enter more than one number to be tested for repeated digits. The program should terminate when the user enters a number that is less than 0. Here is a sample output: Enter a number (-1 to end this loop): 41271092 Digit: 0 1 2 3 4 5 6 7 8...

  • 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...

  • Write an application in java that reads in a five-digit integer and determines whether it is...

    Write an application in java that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Tips: 1. Determine the number of digits in the value input by the user , i.e. prompt the user to enter the number of digits of the number. Use a while loop to determine whether the user input contains the proper...

  • C++ Write a complete program that will prompt the user for a digit in the range...

    C++ Write a complete program that will prompt the user for a digit in the range 5 to 15. Using that digit to determin scale display the graphic shown below. Your program must use a nested loop. You may not use the string class SAMPLE RUN: Input an integer in the range 5 to 20: 100 Incorrect. The number is out of range. Input an integer in the range 5 to 20: 10 * ** *** **** ***** ****** *******...

  • In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • Write a program that receives a positive integer n from the user and then calculates the...

    Write a program that receives a positive integer n from the user and then calculates the sum below by using a loop. Your program needs to ask the user to re-enter a different number if the user enters a non-positive one. Display the result. 1 SUM 1 2 3 ... n x x n = = = + + + +

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