setBit

 #include <iostream>

using namespace std;


int setBit(int n){

    int count=0;

    while(n/2!=0){

        if(n%2==1){

            count=count+1;

        }

        n=n/2;

        

    }

    if(n==1){

        count=count+1;

    }

    return count;

}

int main() {

    cout<<setBit(3);


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings