a) What output will be printed for input value x = 8 ? (b) How many dierent input values x cause the function to print the result 8 ? (c) Write a function with the same behavior but only one loop (of any type) and no library call except for the print statement.
a) What output will be printed for input value x = 8 ? (b) How many dierent input values x cause the function to print the result 8 ? (c) Write a function with the same behavior but only one loop (of any type) and no library call except for the print statement.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
Related questions
Question
Consider the following C function or Java method (except for final print
statement the code is the same):
void fun (int x) {
int a, b, c, d;
d = 1;
for (a = 1 ; a <= x ; a ++) {
b = a;
c = 1;
while (b > 0) {
c &= b % 2;
b /= 2;
}
d += c;
}
printf ("%d\n", d);
}
void fun (int x) {
int a, b, c, d;
d = 1;
for (a = 1 ; a <= x ; a ++) {
b = a;
c = 1;
while (b > 0) {
c &= b % 2;
b /= 2;
}
d += c;
}
System.out.println (d);
}
(a) What output will be printed for input value x = 8 ?
(b) How many dierent input values x cause the function to print the
result 8 ?
(c) Write a function with the same behavior but only one loop (of any
type) and no library call except for the print statement.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 1 images
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
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning