int main()
{
int n;
scanf("%d",&n);
printf("%d",getval(n));
return 0;
}
int getval(int n)
{if(n==0)
return 0;
else
{
int temp=getval(n&n-1);
temp++;
return temp;
}
}
most probably the code was this.if it is wrong,somebody who appeared
in the test plz correct it.
Thanks
Gaurav
it calculates total number of 1's in n.On Sun, Nov 22, 2009 at 7:02 PM, Ajay <ajay....@gmail.com> wrote:
I think its calculating the number of bits set in the number.On Sun, Nov 22, 2009 at 11:57 PM, gaurav kejriwal <gaur...@gmail.com> wrote:
Hi,
There was question in the written test of chakpak to depict what the
following piece of code is doing.Somebody plz give the solution.
int main()
{
int n;
scanf("%d",&n);
printf("%d",getval(n));
return 0;
}
int getval(int n)
{if(n==0)
return 0;
else
{
int temp=getval(n&n-1);
temp++;
return temp;
}
}
most probably the code was this.if it is wrong,somebody who appeared
in the test plz correct it.
Thanks
Gaurav
VIPUL AGRAWALAjay Kr. Gautam
--
IDD, Part V
Dept. of Computer Science & Engg., IT-BHU
Varanasi-221005, UP
India
--
IDD IV Yr. , Department of Computer Science & Engineering
IT BHU , Varanasi
Contacts
Phone No: +919795686718
e-mail :
vipul.agr...@itbhu.ac.in
vipul....@gmail.com