LightOj 1182-Parity

#include <stdio.h>
int main ()
{
    int a[10000],i,dec,t,c,j,k;
    while(scanf("%d",&t)!=EOF)
    {
        for(k=1;k<=t;k++)
        {
          scanf("%d",&dec);
            i=0;
            c=0;
        while(dec>0)
        {
            a[i]=dec%2;
            i++;
            dec=dec/2;

        }
        for(j=i-1;j>=0;j--)
        {
            if(a[j]==1)
            {
                c++;
            }
        }
        if((c%2)!=0)
        {

            printf("Case %d: odd\n",k);
        }
        else
        {
            printf("Case %d: even\n",k);
        }
    }
    return 0;

}
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment