Question
C++ Program using recursion. QUESTION: /** * A program that takes in a positive integer n, then * outputs the number of n-digit binary numbers
C++ Program using recursion. QUESTION: /** * A program that takes in a positive integer "n", then * outputs the number of n-digit binary numbers having at * least as many 1's as 0's for any prefix of the number. * * That is, at any point while reading the number left to * right, you've always seen at least as many 1's as 0's. * * So, the first digit must be 1, the first two digits must * be either 11 or 10, the first three digits must be 111, * 110, or 101, etc. * * This program should output the count of total binary * numbers that satisfy the constraint. * * Ex: For `n=4`, the binary numbers that satisfy the given * constraints are 1111, 1110, 1101, 1100, 1011, 1010. Notice * that 1001 is not part of the solution set as the first * three digits break the constraint. * * If you try to run your program on inputs larger than about * 25, it will take a very, very long time. * * As with several of the other problems, you will likely want * a helper function. * * You may not use for, while, do while, or goto. */
Program: #include
int findBin(unsigned int n){ } //do NOT change the main function int main(int argc, char** argv){ unsigned int n; cin >> n; cout << findBin(n) << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started