Question

Every positive integer has a multiple that, when expressed in base ten, is comprised entirely of...

Every positive integer has a multiple that, when expressed in base ten, is comprised entirely of zeros and ones. Write a procedure to find the least multiple of n, the input parameter, which is of the required form.

Warnings: You should definitely use the long data type for this computation. The least multiple of the required form may be much larger than the input n. For example, what is the least such multiple of 9 that contains only zeros and ones? What is the least such multiple of 99?

Design your procedure to detect overflow and return -1 if it is unable to find the required multiple.

solve in c++

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

C++ code:

#include<iostream>
using namespace std;
//function to check whether all digits of n are zero or one
//if all are 0/1 then returns 1
//otherwise returns 0
int check_zero_one(long int n)
{
   int digit;
   while(n!=0)
   {
       digit=n%10;
       n=n/10;
       if(digit>1)
           return(0);
   }
   return(1);
}


//function to find least multiple d of n
//such that d*n contains only 0/1
long int find_multiple_zero_one(long int n)
{
   int i=1;
   while(i>0)
   {
       if(check_zero_one(i*n))
           return(i);
       i++;
   }
   return(-1);
}

//main driver function
int main()
{
   long int n;
   cout<<"Enter a number:";
   cin>>n;
   long int d=find_multiple_zero_one(n);
   cout<<"Least multiple contains 0 or 1 is:"<<d<<endl;
   cout<<"As "<<n<<"*"<<d<<"="<<n*d<<endl;
  
}

output:

Add a comment
Know the answer?
Add Answer to:
Every positive integer has a multiple that, when expressed in base ten, is comprised entirely of...
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
  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • Problem 3: Design Problem On Figure P3a, you have a Common Source (CS) n-channel MOSFET amplifier....

    Problem 3: Design Problem On Figure P3a, you have a Common Source (CS) n-channel MOSFET amplifier. Notice the absence of a source resistor Rsig and load resistor R. If we know how the present amplifier (the one on Figure P3a) behaves without Rsig and RL, we can infer its behaviors if Rsig and R were to be added. design the amplifier circuit on Figure P3a, i.e., you have to find appropriate values for RGj You are to RG,, RD, and...

  • Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In...

    Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In this scheme, some procedure is used to identify when a deadlock occurs, and then another procedure is used to deal with the blocked processes. One technique to identify a deadlock is to maintain a resource graph that identifies all processes, all resources, and the relationships between them (that is, which processes exclusively own which resources, and which processes are blocked waiting for which...

  • The administration of President Barack Obama has made Patient Protection and Affordable Care Act, often called...

    The administration of President Barack Obama has made Patient Protection and Affordable Care Act, often called “Obamacare”, its chief domestic accomplishment and the centerpiece of Obama’s legacy. Essential to Obama’s health care reform plan is Healthcare.gov, a health insurance exchange Web site that facilitates the sale of private health insurance plans to U.S. residents, assists people eligible to sign up for Medicaid, and has a separate marketplace for small businesses. The site allows users to compare prices on health insurance...

  • Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 an...

    Notes for lab dc02-Resistors and the Color Code will skip are Part 2 e, g: Part 4; Exercises 2, 4,5,6 and 3. It is important to answer the exercises correctly in each labl you should include the appropriate prefix for the unit in the Numerical Value We will not be Volt using the Volt-Ohm meter (VOM) for this lab, so skip the parts that ask for VOM measurements. The parts we You do need to complete Exercises1 Note that in...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

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