Count Set Bits in an Integer

Code

#include <stdio.h>\n\nint countSetBits(unsigned int n) {\n    \/\/ Write your code here\n    int i,c=0;\n    for(i=31;i>=0;i--)\n    {\n        if(n&(1<<i))\n        {\n            c++;\n        }\n    }\n    return c;\n}\n\nint main() {\n    int n;\n    scanf(\"%d\", &n);\n    printf(\"%d\", countSetBits(n));\n    return 0;\n}<\/code><\/pre>Solving Approach<\/strong><\/h2> <\/p> <\/p> <\/p>"}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

5

Expected Output

2