Question

5. Write a program that does to perform the following using: Reads a number num that is in the range from 0 to 999999999 and
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>


using namespace std;

int main()
{
long int num;
int n;
cout<<"Enter Number(0 to 999999999)";
cin>>num;
cout<<"Enter Value of n(0 to 9)";
cin>>n;
cout<<"\n";
while(num>999999999 && num>0)
{

cout<<"Enter the values of num within range";
cout<<"Enter Number(0 to 999999999)";
cin>>num;

}
while( n>9 &&n>0)
{

cout<<"Enter the values of n within range";
cout<<"Enter Value of n(0 to 9)";
cin>>n;
}

int count=0,temp;
long int num1=num;
while(num1)
{
temp = num1%10;
num1 = num1/10;
if(temp==n)
count++;
}
cout<<"the digit "<<n<<" appears "<<count<<" number of times in the number "<<num;
return 0;
}

OUTPUT

Enter Number(0 to 999999999)555559089 Enter Value of n(0 to 9)5 the digit 5 appears 5 number of times in the number 555559089

Add a comment
Know the answer?
Add Answer to:
5. Write a program that does to perform the following using: Reads a number num that...
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
  • 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...

  • Problem 1: Write a program that reads a positive float number and displays the previous and...

    Problem 1: Write a program that reads a positive float number and displays the previous and next integers. Sample Run: Enter a float: 3.5 The previous and next integers are 3 and 4. Problem 2: Write a program that reads two integers and displays their sum, difference, product, and the result of their division. Sample Run: Enter two integers: 8 5 Sum: 8, Difference: 3, Product: 40, Division: 1.6 Problem 3: Write a program that reads a three-digit integer from...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • Write a program that reads an integer k from user and finds the number of elements...

    Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assignment4.txt. A number n is divisible by k if n = kx for some integer x > 0. You can use the mod operator % to test for divisibility. The file assign4.txt has integer values in the range [0,100 ]. You should use end-of-file controlled loop for this problem. Sample execution is given below. Assume the...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() -...

    Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() - Prints out the contents of the file "myfile.txt", that was read into a list by readlines(). Note that this should not look like a list, so you will need to loop through the list created by readlines and print the text. - Use the try/except method to create the file if it does not exist - If the file does not exist, prompt the...

  • How to I solve this using modulo? Problem 1: Develop a C program that reads a...

    How to I solve this using modulo? Problem 1: Develop a C program that reads a file of integers called “numbers.txt” It then prints the occurrence count of each digit from [0-9]. Your code must utilize the following function: void freqFun (int num, int counters[]) In this prototype, num represents the number read from the file and counters represents the set of counters that hold the occurrence frequency of each digit. Digits that do not occur in the file shall...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

  • Using emu8086.inc , write an assembly program that display the message 'Enter the number:' Then, reads...

    Using emu8086.inc , write an assembly program that display the message 'Enter the number:' Then, reads a byte from the user, then count the number of 1’s in it, and display them on screen.

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