click below for solution

Wednesday, 26 January 2022

The Final Task Solution|Bi Wizard School coding Tournament Solution


Your Task:

Your task is to complete the function count_set_bits() which takes an integer array arr as the first argument and the integer n representing the size of the array as the second argument and returns an integer which represents the total count of 1's in the binary representation of each element of the array.


Solution:

int count_set_bits(int *arr, int n) {

    // Write your code here..

    long long c=0;

    for(long long i=0;i<n;i++){

        long long x=arr[i],rem=0,dec=0,j=0;

        while(x>0)

        {

            long long rem=x%2;

            dec=dec*10+rem;

            x/=2;

        }

        while(dec>0){

            long long rem=dec%10;

            if(rem==1){

                c++;

            }

            dec/=10;

        }

        

    }

    return c;

}

5 comments:

  1. this is not working

    ReplyDelete
    Replies
    1. Solution come within contest time .but you have to follow our blog to get notification of solution .if you follow our blog then get notification when answer in updated in blog.so click on follow button.also follow on our youtube channel for furture notification.

      Delete
  2. Replies
    1. Solution come within contest time .but you have to follow our blog to get notification of solution .if you follow our blog then get notification when answer in updated in blog.so click on follow button.also follow on our youtube channel for furture notification.

      Delete
  3. Solution come within contest time .but you have to follow our blog to get notification of solution .if you follow our blog then get notification when answer in updated in blog.so click on follow button.also follow on our youtube channel for furture notification.

    ReplyDelete