4. Consider the following C function or Java method (except for final print statement the code...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. 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++) { ba; 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 r = 8? (b) How many different input values r 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. 4. 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++) { ba; 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 r = 8? (b) How many different input values r 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 Answer:
Answer rating: 100% (QA)
In C programming a function is a selfcontained block of code that performs a specific task or a set ... View the full answer
Related Book For
Statistics Principles And Methods
ISBN: 9781119497110
8th Edition
Authors: Richard A. Johnson, Gouri K. Bhattacharyya
Posted Date:
Students also viewed these programming questions
-
What is a function calling convention and how does it impact the design of the RISC-V instruction set architecture (ISA)? [4 marks] (d) Consider the following C function that computes the greatest...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Answer question 43 again for an option with t = .3 years. How does the time until the option expires affect the value of the call option? Question 43 Use the BlackScholes option pricing formula to...
-
What are Kodak's competitively important resources and capabilities? Which of its resources have the greatest competitive power? Are any of its resources and capabilities able to pass all four VRIN...
-
Consider an LTI system with impulse response h(n) = (1/2)n u(n). (a) Determine and sketch the magnitude and phase response |H (?)| (b) Determine and sketch the magnitude and phase spectra for the...
-
The dimensions of the rectangular loop of wire in Figure P29.35 are \(\ell=400 \mathrm{~mm}\) and \(w=120 \mathrm{~mm}\). The mass of the loop is \(10 \mathrm{~g}\), its resistance is \(5.0...
-
After the results of interviews, questionnaires, and prototyping are gathered and analyzed, Anna and Chip move to the next step, modeling the system. Their strategy is to create a layered set of data...
-
18 years ago, I purchased 185 shares of a stock worth $14.25 per share. There was a 2:1 split, a 4:1 split, and a 3:1 split during that time period. Today the stock is worth $1.53 per share. If the...
-
Sarah can bicycle a loop around the north part of Lake Washington in 2 hours and 40 minutes. If she could increase her average speed by 1 km/hr, it would reduce her time around the loop by 6 minutes....
-
Two species of salamanders, Plethodon cinereus and Plethodon hoffmani, overlap in parts of their range in the eastern United States. The two species are very similar in size except in places where...
-
The egg is a large cell and contributes almost all the nutrients present in a fertilized egg. The sperm contributes little more than its set of chromosomes. Just how much bigger is a human egg than a...
-
For a particular scientific experiment, it is important to be completely isolated from any magnetic field, including the earth's field. The earth's field is approximately \(50 \mu \mathrm{T}\), but...
-
The peak current through a capacitor is \(2.0 \mathrm{~A}\). What is the peak current if a. The peak emf \(\mathcal{E}_{0}\) is doubled? b. The capacitance \(C\) is doubled? c. The frequency \(f\) is...
-
A bird is perched on the wire with its feet \(2.0 \mathrm{~cm}\) apart. What INT BIO is the potential difference between its feet? Concern a high-voltage transmission line. Such lines are made of...
-
Mutations resulting in reduced (a) globin chain production from 3 copies of the gene causes one of the following genetic disorders O alpha thalassemia beta thalassimia O hemophilia A O hemophilia B
-
State whether each of the following will increase or decrease the power of a one-way between-subjects ANOVA. (a) The effect size increases. (b) Mean square error decreases. (c) Mean square between...
-
Consider the data on a response variable and two predictor variables. (a) Fit a multiple regression model with response variable y. (b) Verify your answer using software. X2 y -1 -1 -1 1 1 10 -1 11...
-
The amount of municipal solid waste created has become a major problem. According to the Environmental Protection Agency, the yearly amounts (millions of tons) are: (a) Plot the amount of garbage (...
-
Three male and three female students recorded the number of times they used a credit card in one week. (a) Calculate s 2 pooled . (b) Give an estimate of the common standard deviation for the number...
-
A wind turbine works by slowing the air that passes its blades and converting much of the extracted kinetic energy to electric energy. A large wind turbine has 45-m-radius blades. In typical...
-
You are pulling a child in a wagon. The rope handle is inclined upward at a 60 angle. The tension in the handle is 20 N. How much work do you do if you pull the wagon 100 m at a constant speed?
-
A typical muscle fiber is 2.0 cm long and has a cross-section area of 3.1 10-9 m 2 . When the muscle fiber is stimulated, it pulls with a force of 1.2 mN. What is the work done by the muscle fiber...
Study smarter with the SolutionInn App