Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. (20 points) Here are four C propraus that connt the bits on in an integer; that is, you rum '. cb5 ' and it

image text in transcribed
6. (20 points) Here are four C propraus that connt the bits on in an integer; that is, you rum '. cb5 ' and it will print '2' (because 5 in binary is 101, and two bits are turned on). For each proyram, indicate whether it works. If it does not, show how to fix it by changing the feurest characters possible, Note that these programs will crash if not given an argument; that's not considered an error per the design spec. Program A Works as is. Needs fixing. \#include int main (int arge, char *argv[) f // warning: assumes argv[1]! int val =atoi(argv[1]); int sum =0; for (int 1=0;1=0;i ) if (val &1i ) sum +=1; printf ("\%d ", sum); \} Program C Works as is, Needs fixing. *include "include int main(int argc, char *argv[) c // warning: assumes argv[1]! int val = atoi(argv[1]); int sum =0; while ( val ) 1 if (val \#include int main(int argc, char *argv [ ) i // warning: assumes argv[1]! int val =strtoul(argv[1], NULL, 10) int suen =0; while (val) \{ sum +=val&1; val =1; \} printf (" //d ", sum); \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

=+3. Draw the submodels of an integrated business model!

Answered: 1 week ago