Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
2.A. Is it possible to pass variable y as parameter to the functions? 2.B. Supply the missing code stated in TODO at line 17-19. 2.C Supply the missing code stated in TODO at line 21-22. 2.D. (Assuming the code is complete) What will be the display of this program?
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