Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 20, Problem 12RQE
#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;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ Functions provide a means to modularize applications
Write a function called "Calculate"
takes two double arguments
returns a double result
For example, the following is a function that takes a single "double" argument and returns a "double" result
double squareArea(double side){ double lArea; lArea = side * side; return lArea;}
#include
using namespace std;
|| function declaration
int max(int num1, int num2);
int main () {
// local variable declaration:
int a = 100;
int b = 200;
int ret;
I| calling a function to get max value.
ret = max(a, b);
cout num2)
result = num1;
else
result = num2;
return result;
}
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
Chapter 20 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 20.2 - What happens if a recursive function never...Ch. 20.2 - What is a recursive functions base case?Ch. 20.2 - Prob. 20.3CPCh. 20.2 - What is the difference between direct and indirect...Ch. 20 - What is the base case of each of the recursive...Ch. 20 - What type of recursive function do you think would...Ch. 20 - Which repetition approach is less efficient, a...Ch. 20 - When should you choose a recursive algorithm over...Ch. 20 - Explain what is likely to happen when a recursive...Ch. 20 - The _____________ of recursion is the number of...
Ch. 20 - Prob. 7RQECh. 20 - Prob. 8RQECh. 20 - Prob. 9RQECh. 20 - Write a recursive function to return the number of...Ch. 20 - Write a recursive function to return the largest...Ch. 20 - #include iostream using namespace std; int...Ch. 20 - Prob. 13RQECh. 20 - #include iostream #include string using namespace...Ch. 20 - Iterative Factorial Write an iterative version...Ch. 20 - Prob. 2PCCh. 20 - Prob. 3PCCh. 20 - Recursive Array Sum Write a function that accepts...Ch. 20 - Prob. 5PCCh. 20 - Prob. 6PCCh. 20 - Prob. 7PCCh. 20 - Prob. 8PCCh. 20 - Prob. 9PCCh. 20 - Prob. 10PCCh. 20 - Prob. 11PCCh. 20 - Ackermanns Function Ackermanns Function is a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Explain what serializable isolation level is. Give an example of its use.
Database Concepts (8th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Revise the definition of the method writeOutput in Listing 5.3, using the keyword this. Do not change the meani...
Java: An Introduction to Problem Solving and Programming (7th Edition)
Write a program to print the value of EOF.
C Programming Language
A variable that is visible to every function in a program file is a __________. a. local variable b. universal ...
Starting Out with Python (4th Edition)
Will the following string literal fit in the space allocated for name? Why or why not? Char name [4] = "John";
Starting Out with C++: Early Objects
Knowledge Booster
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
- Nonearrow_forwardNonearrow_forwardint func(int a, int b) { return (aarrow_forwardDefine the term " pointer to function " .arrow_forwardSTRUCTURES IN C The circle has two data members, a Point representing the center of the circle and a float value representing the radius as shown below. typedef struct{ Point center; float radius;} Circle; typedef struct{ int x; int y;}Point; Implement the following functions:a. float distance (Line l1);- computes and returns the distance between the two points of the line.distance = sqrt((x2-x1)^2+(y2-y1)^2) b. float diameter(Circle circ);- computes the diameter of a circle.arrow_forwardC++ Coding: ArraysTrue and False Code function definitions for eoNum() and output(): Both eoNum() and output() are recursive functions. output() stores the even/odd value in an array. Store 0 if the element in the data array is even and store 1 if the element in the data array is odd. eoNum() displays all the values in an array to the console.arrow_forward#include using namespace std; // FUNCTION PROTOTYPE int my_fun (int, int&, int); int main () { int x = 4, y = -2, z = 3; x = my_fun (x, y, z); cout << "In main, x = " « x « ", y = " <« y << and z = " << z << endl; return 0; } // FUNCTION DEFINITION int my_fun (int a, int&b, int c) { a = 2 * a + b; b += c; c++; a = " << a <« ", b = " <« b << endl; cout << "In my fun, a = " return a % 2; }arrow_forwardWhen an array is passed as an actual parameter to a function, what is actually being passed?arrow_forwardli en aretle Let the functions fun and main be defined as int fun(int *k) { *k += 2, return (*k) - 1; } void main() { int i = 10, j = 10, suml, sum2; suml= (1/2) + fun(&i); sum2 = fun(&j) + (j/2) +i; } What are the values of sum1 and sum2 at the end of the main function. a. operands in the expressions are evaluated left to right? suml= sum2- b. operands in the expressions are evaluated right to left? suml= sum2= UYGULAMAYI BİTİR...arrow_forwardFunctions With Parameters and No Return Values Quiz by CodeChum Admin Create a program that accepts an integer N, and pass it to the function generatePattern. generatePattern() function which has the following description: Return type - void Parameter - integer n This function prints a right triangular pattern of letter 'T' based on the value of n. The top of the triangle starts with 1 and increments by one down on the next line until the integer n. For each row of in printing the right triangle, print "T" for n times. In the main function, call the generatePattern() function. Input 1. One line containing an integer Output Enter·N:·4 T TT TTT TTTTarrow_forwardQuestion p .C language program Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardmodule 4: Differentiate between Writing Functions for Array and Writing Functions for Structures.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License