From c24973af02bc33f2f5f25d37e22ca91da5de3c47 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 4 Jun 2022 12:11:15 +0530 Subject: inital commit --- 2.9.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 2.9.c (limited to '2.9.c') diff --git a/2.9.c b/2.9.c new file mode 100644 index 0000000..5a0ceb9 --- /dev/null +++ b/2.9.c @@ -0,0 +1,23 @@ +#include + +int bitcount(unsigned num); + +int +main(void) +{ + int x = 1337; /* a random int */ + printf("%d\n", bitcount(x));; + + return 0; +} + +int +bitcount(unsigned num) +{ + int bits; + + for (bits = 0; num != 0; num &= (num-1)) + bits++; + + return bits; +} -- cgit v1.2.3