a) What output will be printed for input value x = 8 ? (b) How many di erent 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
icon
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 di erent 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.

. 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;
1
d - 13;
for (a - 1; a c-I ; a +) {
b - a;
C- 1:
while (b > 0) {
c &- b % 2;
b /- 2;
d +- c;
printf ("Xd\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 k- b % 2;
b /- 2;
d - c;
Systen.out.println (d);
(a) What output will be printed for input value r =8?
(b) How marny different input values z cause the function to print the
result 8?
(e) Write a function with the same behavior but only one loop (of any
type) and no library call except for the print statement.
Transcribed Image Text:. 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; 1 d - 13; for (a - 1; a c-I ; a +) { b - a; C- 1: while (b > 0) { c &- b % 2; b /- 2; d +- c; printf ("Xd\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 k- b % 2; b /- 2; d - c; Systen.out.println (d); (a) What output will be printed for input value r =8? (b) How marny different input values z cause the function to print the result 8? (e) 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
steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Hiring Problem
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning