Created
December 30, 2013 09:29
-
-
Save atondwal/8179801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cstdlib> | |
using namespace std; | |
int bits(int x){ | |
if(!x) return x; | |
return (x&1)+bits(x>>1); | |
} | |
int main(int argc, char const* argv[]) | |
{ | |
int x = atoi(argv[1]); | |
cout << bits(x) <<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment