Predict the Output
What is the output of the following programs?
A) #include
using namespace std;
int function(int);
int main()
{
int x = 10;
cout << function(x) << endl;
return 0;
}
int function(int num)
{
if (num <= 0)
return 0;
else
return function(num - 1) + num;
}
B) #include
using namespace std;
void function(int);
int main()
{
int x = 10;
function(x);
return 0;
}
void function(int num)
{
if (num > 0)
{
for (int x = 0; x < num; x++)
cout << '*';
cout << endl;
function(num - 1);
}
}
C) #include
#include
#include
using namespace std;
void function(string str, int pos);
int main(int argc, char** argv)
{
string names = "Adam and Eve";
function(names, 0);
return 0;
}
void function (string str, int pos)
{
if (pos < str.length())
{
function(str, pos+1);
cout << str[pos];
}
}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.