Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 14, Problem 7RQE

Predict the Output

7. What is the output of the following programs?

A) #include <iostream>

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 <iostream>

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 <cstdlib>

#include <string>

#include <iostream>

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]:

}

}

Blurred answer
Students have asked these similar questions
14. What is the value of a and b after the function call myfunction1(a,b) in the main function? void myfunction1(int a, int &b) { a+t; b++; int main() { int a=5,b=53; myfunction1(a,b): } a) a=5,b=5 b) a=5,b=6 c) a=6,b=5 d) a=6,b=6
func(X) {return x++;} void func(x) {printf("hi");} QUESTION 14 Which is from the following is not a function prototype? int funct(char x, char y); funct(x); void funct(void); char x(int y); Click Save and Submit to save and submit. Click Save All Answers to save all ai
#include using namespace std; void myfunction(int num2, int num1); lint main() { my function (5,2); return 0; } void myfunction(int num1, int num2) {if (num1>3) cout << "A1"; else if (num1<3) cout<<"A2"; else cout<<"A3";} O A2 O A1 O A3 A1 A2 A3

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY