Example:
Starting num = 2
Next num = 3
It should then print 3 4 5
Given code:
#include <iostream>
using namespace std;
void slowDisplay(int, int);
int main(void) {
int start, nextCount;
cout << "Enter starting integer: ";
cin >> start;
cout << "Enter how many next integers: ";
cin >> nextCount;
slowDisplay(start + 1, nextCount);
return 0;
}
void slowDisplay(int start, int nextCount) {
// TODO: Add the base case here
if(start == 0) {
cout << start << " ";
slowDisplay(start + 1, nextCount - 1);
}
}
#include <iostream>
using namespace std;
void slowDisplay(int, int);
int main(void)
{
int start, nextCount;
cout << "Enter starting integer: ";
cin >> start;
cout << "Enter how many next integers: ";
cin >> nextCount;
slowDisplay(start + 1, nextCount);
return 0;
}
void slowDisplay(int start, int nextCount)
{
if (start > 0&&nextCount>0)
{
cout << start<<" ";
slowDisplay(start + 1, nextCount - 1);
}
if (start == 0)
{
cout << start << " ";
slowDisplay(start + 1, nextCount - 1);
}
}
Comments
Leave a comment