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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education