View Problem
View Code
#include<stdio.h>
int main()
{
long long int num,count,i,s,x,l;
char str[200000];
long long int value[200000];
while(scanf("%lld",&num)==1)
{
if(num==0)
break;
if(num==1)
printf("The parity of 1 is 1 (mod 2).\n");
else{
count=0;
i=0;
while(num!=0)
{
if(num%2==1)
count++;
s=num/2;
value[i++]=num%2;
num=s;
}
x=0;
for(l=i-1;l>=0;l--)
str[x++]=value[l]+'0';
str[x]='\0';
printf("The parity of %s is %lld (mod 2).\n",str,count);
}
}
return 0;
}
View Code
#include<stdio.h>
int main()
{
long long int num,count,i,s,x,l;
char str[200000];
long long int value[200000];
while(scanf("%lld",&num)==1)
{
if(num==0)
break;
if(num==1)
printf("The parity of 1 is 1 (mod 2).\n");
else{
count=0;
i=0;
while(num!=0)
{
if(num%2==1)
count++;
s=num/2;
value[i++]=num%2;
num=s;
}
x=0;
for(l=i-1;l>=0;l--)
str[x++]=value[l]+'0';
str[x]='\0';
printf("The parity of %s is %lld (mod 2).\n",str,count);
}
}
return 0;
}
No comments:
Post a Comment