C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 18SA
(a)
Program Plan Intro
To determine the possible output, when the function call mystery(4, -5) will be generated.
(b)
Program Plan Intro
To determine the possible output, when the function call mystery(-8, 9) will be generated.
(c)
Program Plan Intro
To determine the possible output, when the function call mystery(2,3) will be generated.
(d)
Program Plan Intro
To determine the possible output, when the function call mystery(-2,-4) will be generated.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C Program:
An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. I have written a function called isPerfect (see below), that determines whether parameter passed to the function is a perfect number. Use this function in a C program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect.
// isPerfect returns true if value is perfect integer,
// i.e., if value is equal to sum of its factors
int isPerfect(int value)
{
int factorSum = 1; // current sum of factors
// loop through possible factor values
for (int i = 2; i <= value / 2; ++i) {
// if i is factor
if (value % i == 0) {
factorSum += i; // add to sum
}
}
// return true if value is equal to sum of factors
if (factorSum == value) {
return…
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
*In C program, what is wrong with the following function?
int integer_add( int x, int y, int z )
{
int sum;
sum = x + y + z:
return sum;
}
Chapter 6 Solutions
C++ Programming: From Problem Analysis to Program Design
Ch. 6 - Mark the following statements as true or false:
a....Ch. 6 - Determine the value of each of the following...Ch. 6 - Determine the value of each of the following...Ch. 6 - Consider the following function definition. (4, 6)...Ch. 6 - Consider the following statements:
Which of the...Ch. 6 - Prob. 8SACh. 6 - Prob. 9SACh. 6 - Why do you need to include function prototypes in...Ch. 6 - Prob. 11SACh. 6 - Consider the following function: (4)...
Ch. 6 - Prob. 15SACh. 6 - What is the output of the following program? (4)
Ch. 6 - Write the definition of a function that takes as...Ch. 6 - Prob. 18SACh. 6 - How would you use a return statement in a void...Ch. 6 - Prob. 20SACh. 6 - Prob. 21SACh. 6 - What is the output of the following program?...Ch. 6 - Write the definition of a void function that takes...Ch. 6 - Write the definition of a void function that takes...Ch. 6 - Prob. 8PECh. 6 - The following formula gives the distance between...Ch. 6 - Write a program that takes as input five numbers...Ch. 6 - When you borrow money to buy a house, a car, or...Ch. 6 - Consider the definition of the function main:...Ch. 6 - The statements in the following program are not in...Ch. 6 - Write a program that outputs inflation rates for...Ch. 6 - Write a program to convert the time from 24-hour...Ch. 6 - Jason opened a coffee shop at the beach and sells...
Knowledge Booster
Similar questions
- C++ PROGRAMMING PART C Please help me i am stressing so much on this. I would really appreciate it. THIS was the code provided to me to help me solve the question. const int N =31; // N parking spaces bool parking[N]; // the garage void EmptyTheLot(bool parking[], int N) { for(int i=0; i<N; i++) p[i]=false; // empty space } // returns -1 if no space found, //otherwise it returns 0<=i<N for a valid space. int FindSpace(int PlateNumber, bool parking[], int N) { // ????? } main() { EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot. }arrow_forwardPerform in C#arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 1. Write a recursive function named printStars which receives an int parameter. If the parameter is positive, the function prints the given number of asterisks; otherwise the function does nothing. The function does not return a value. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed. The function must not use a loop of any kind to accomplish its job. Instead, it gets the job done by (recursively) calling itself.arrow_forward
- Programming Language :- C 7. A function is defined for a positive integer n as follows: 3n + 1, if n is odd f(n) = { n if n is even 2 We consider the repeated application of the function starting with a given integer n, as follows: f(n), f(f(n)), f(f(f(n))), It is conjectured that no matter which positive integer n you start from; this sequence eventually will reach to 1. If n = 13, the sequence will be 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. Thus if you start from n = 13, you need to apply function 10 times to reach 1. Write a recursive function that takes n as an input number and returns how many times function f has to be applied repeatedly to reach 1.arrow_forwardWrite a recursive function definition for the following function: int squares(int n); //Precondition: n >= 1 //Returns the sum of the squares of numbers 1 through n. For example, squares(3) returns 14 because 12 + 22 + 32 is 14.arrow_forwardC Programming "Functions"arrow_forward
- Computer Science need help plzarrow_forwardProblem: Recursive Power Method Design a python function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised, and the exponent. Assume the exponent is a nonnegative integer. Write the main() function to input the required parameters as shown in thesample input/output. Sample Output:Average number of words per line: 26.0Enter a number: 2Enter a positive whole number between 1 and 100: 102.0 raised to the power of 10 is 1,024.00arrow_forwardIn C programing Write a recursive function that returns the product of the digits of its integer input parameter, n. You may assume that n is non-negative. For example, productDigits(243) should return 24, since 2 x 4 x 3 = 24.int productDigits (int n) {arrow_forward
- In C++ Consider the following recursive function (Chapter 17, #9, modified) void recFun(int x) { if (x > 10) { recFun(x / 10); cout<< x % 10; } else cout<< x; } How can the code be modified so that the sum of all digits is printed?arrow_forwardint func(int a, int b) { return (aarrow_forwardC programming please complete (a),(b),(c)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