Question
Assume that x is a variable that has been declared as an int and been given a value. Assume that twice is a function that receives a single integer parameter and returns twice its value. (So if you pass 7 to twice it will return 14. Thus the expression twice(7) has the value 14.
Write an expression whose value is eight times that of x without using the standard C arithmetic operators (*,+, etc.). Instead, use calls to twice to accomplish this.
In this exercise you must write this as a single expression-- you must not write any statements. Also, you may only use the twice() function-- no other functions or operators.
Solution
twice(twice(twice(x)))
Answers for C++ Course using "Starting out with C++ : from control structures through objects" by Tony Gaddis. 7/8th ed. I used the Pearson myprogramminglab to complete the homework. Here are my solutions/answers for the exercises/labs so please use the test bank as a GUIDE if you're stuck. Let me know if you find a better solution to a problem or any of the programming challenges. Thanks in advance for your support! Send in missing programming challenges to cplusplus.answers@gmail.com
MPL Extra: Composition: 10778
Question
Assume the availability of a function named oneMore . This function receives an integer and returns one more than its parameter. So, pass oneMore(12 ) and it will return 13. DO NOT DEFINE this function-- just assume it is available. YOUR TASK: write an expression whose value is 5 but in your expression you can only use the integer literal 0. You can not use anything with the digits 1-9 and you cannot use any arithmetic operators like +-*/. But you can use 0 and you can make calls to the function oneMore.
Solution
oneMore(oneMore(oneMore(oneMore(oneMore(0)))))
Assume the availability of a function named oneMore . This function receives an integer and returns one more than its parameter. So, pass oneMore(12 ) and it will return 13. DO NOT DEFINE this function-- just assume it is available. YOUR TASK: write an expression whose value is 5 but in your expression you can only use the integer literal 0. You can not use anything with the digits 1-9 and you cannot use any arithmetic operators like +-*/. But you can use 0 and you can make calls to the function oneMore.
Solution
oneMore(oneMore(oneMore(oneMore(oneMore(0)))))
Subscribe to:
Posts (Atom)