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
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
C PROGRAM  Reverse + Random Formula In the code editor, there's already an initial code that contains the function declaration of the function, computeReverseNumber(int n) and an empty main() function. For this problem, you are task to implement the computeReverseNumber function. This function will take in an integer n as its parameter. This will get the reverse of the passed integer and will then compute and return the value: result = (original_number + reverse_of_the_number) / 3 In the main() function, ask the user to input the value of n, call the function computeReverseNumber and pass the inputted value of n, and print the result in the main() with two (2) decimal places. SAMPLE: Input n: 20 Output: 7.33   Input n: 123 Output: 148.00

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