Write in C++ only A1.txt file contains Thank you Program 1 - 25 pts 1. An input
ID: 3687824 • Letter: W
Question
Write in C++ only
A1.txt file contains
Thank you
Program 1 - 25 pts 1. An input file A1.txt is given where each line consists of two integers: n and r. 2. Read each line of the input file using a loop and perform the following operations: (a) If n is a positive integer and r is a nonnegative integer where r n, then print 'r > n error Note: You have to read the file using loops. The number of lines in Al.txt can be more than 10 1 Sample input: 2 7 2 s Sample output: G7 2 42 21 78 9 r>n errorExplanation / Answer
void combinations_r_recursive(
const vector<char> &elems,
unsigned long req_len,
vector<unsigned long> &pos,
unsigned long depth,
unsigned long margin
)
{
// Have we selected the number of required elements?
if (depth >= req_len) {
for (unsigned long ii = 0; ii < pos.size(); ++ii)
cout << elems[pos[ii]];
cout << endl;
return;
}
// Try to select new elements in the same position or
// to the right of the last selected one.
for (unsigned long ii = margin; ii < elems.size(); ++ii) {
pos[depth] = ii;
combinations_r_recursive(elems, req_len, pos, depth + 1, ii);
}
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.