Playing with bits

I don’t know why my code isn’t working can you help me please.

#include
using namespace std;

/*
void getSetBits(int arr[], int n)
{
int len = 2*n;
if(n==1)
{
int count=0;
for(int i=arr[0]; i< arr[1]; i++)
{
while(i!=0)
{
if(i&1)
{
count++;
}
i = i>>1;
}
}
}

for(int i=0; i<len; i+2)
{
    int start = arr[i];
    int end = arr[i+1];
    int count = 0;
   
    for(int j=start+1; j<end; j++)
    {   
        while(j!=0)
        {
            if(j&1)
            {
                count++;
            }
            j=j>>1;
        }
    }
    cout << count << endl;
}

}
/
void printArray(int arr[], int n)
{
for(int i=0; i<2
n; i++)
{
cout << arr[i] << " ";
cout << endl;
}
}

void getSetBits(int arr[], int n, int start, int end)
{
int len = 2*n;

if(start>=len-1)
{
    return;
}

int count = 0;

for(int i = arr[start]+1; i<arr[end]; i++)
{
    while(i!=0)
    {
        if(i&1)
        {
            count++;
        }
        i = i>>1;
    }
}

cout << count << endl;

getSetBits(arr, n, start+2, end+2);

}

int main() {
int n;
cin >> n;

int len = n*2;
int arr[len];

for(int i=0; i<2*n; i++)
{
    cin >> arr[i];
}

getSetBits(arr, n, 0, 1);
// printArray(arr, n);
// getSetBits(arr, n);
return 0;
}

Hello @Udit-Sehra-2366292823468769,

Please, share your code using Online Coding Blocks IDE.
STEPS:

  1. Paste your code at https://ide.codingblocks.com/
  2. Save your code there.
  3. Share the URL generated.

The way you have shared it may introduce syntax error.

Here’s the link.

Hello @Udit-Sehra-2366292823468769,

There are two mistakes in your code:
I have corrected both:


Refer to the comments for better understanding.

Hope, this would help.
Give a like if you are satisfied.