Question: 6. ( 20 points) Here are fou C programs that count the bits on in an integer, that is, you rum ' ( Cb5 '

 6. ( 20 points) Here are fou C programs that count

6. ( 20 points) Here are fou C programs that count the bits on in an integer, that is, you rum ' ( Cb5 ' and it will print ' 2 ' (becatse 5 in binary is 101 , and two bits are turned on). For each program, indicato whether it works. If it does not, show how to fix it by changing the fevest 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 D. Works as is. Needs fixing. IInclude stdio, h> "include stdlib. b> int cain( int argc, char *argu[) f // varning: assumes argv[1]! int val =atoi(argv[1]); int suan =0; for (int 1=0;1m0;1 ) if (val \& 11 ) sum t=1; printf ("\%d ", sum); \} Program C Works as is. Neeris tixing: "include sitdio. h> "include int main(int argc, char *argv[]) t. // rarning: assutes argv[1]! int sum=0; while ( val) f if ( val \#include stdiib.h> int main(int arge, char *argv[]) i // warning: assumes argr [1]! int val=strtoul(argv[1], NULL., 10) int sum=0; while (val) ( sum+= val \& 1 ; val 0 1; \} printf("\%d ", sum); \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!