@DOn can u explain ur first algo, it would be helpful.

On Wed, May 22, 2013 at 7:28 PM, Don <dondod...@gmail.com> wrote:

> My program works with any numbers.
> Don
>
> On May 22, 3:45 am, Pramida Tumma <pramida.tu...@gmail.com> wrote:
> > This above program works only if the array contains consecutive numbers
> > starting from 1 to n. What to do if the array contains random numbers?
> >
> >
> >
> >
> >
> >
> >
> > On Fri, May 17, 2013 at 6:55 PM, Don <dondod...@gmail.com> wrote:
> > > Counting the set bits in one integer is not the problem which was
> > > asked.
> > > However, I think that something like this is both faster and more easy
> > > to understand than what you have written:
> >
> > > int bitCount(unsigned int x)
> > > {
> > >    int result = 0;
> > >    while(x)
> > >    {
> > >       if (x & 1) ++result;
> > >       x >>= 1;
> > >    }
> > >    return result;
> > > }
> >
> > > On May 17, 8:32 am, bhargav <ybbkris...@gmail.com> wrote:
> > > > as bitwise operators are fast can count by following logic, works
> oly fr
> > > > +ve, just a tweak will make it to work with -ves also ..
> >
> > > > #include <stdio.h>
> > > > main() {
> > > > unsigned int x=12312,a;
> > > > a=x<<1;
> > > > //printf("%u",a);
> > > > int count=0;
> > > > while(x>0) {
> > > > a = x<<1;
> > > > //printf("%u \n",a);
> > > > if(a<x)
> > > > count++;
> > > > x=a;}
> >
> > > > printf("%d\n",count );
> > > > getch();
> >
> > > > }
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an
> > > email to algogeeks+unsubscr...@googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to