The following error is shown when I try to run the code.
THE CODE is as follow:
image of the code:
#include
using namespace std;
int setbit_between(int s, int e){
int count=0;
for(int i=s;i<=e;i++){
while(i>0){
if(i&1){
count++;
}
i=i>>1;
}
}
cout<<count;
return 0;
}
int main() {
int q;
cin>>q;
while(q–){
int a,b;
cin>>a>>b;
setbit_between(a,b);
}
return 0;
}
whereas
this following code runs fine:
#include
using namespace std;
int countSetBits(int i){
int count=0;
while(i>0){
if(i&1)
count++;
i=i>>1;
}
return count;
}
int main() {
int q;
cin>>q;
while(q–){
int a,b;
cin>>a>>b;
int count =0;
for(int i=a;i<=b;i++){
count+= countSetBits(i);
}
cout<<count<<endl;
}
return 0;
}