Click Here to see the problem detail.
Solution
Read the problem carefully and see source code.
Solution
#include<stdio.h> #include<stdlib.h> int parity; char b[50]; int i; void checkParity(long int n) { i=0; parity=0; if(n) { checkParity(n/2); b[i]=n%2+'0'; if(b[i]=='1') parity++; i++; } b[i]='\0'; } int main() { long int n,i; while(1) { scanf("%ld",&n); if(n==0) break; else { checkParity(n); } printf("The parity of %s is %d (mod 2).\n",b,parity); } return 0; }
Next Previous