#include<stdio.h> #include<stdlib.h> int main() { int m,n; int count=0; int tmp=0; printf("请输入两个任意整数:\n"); scanf("%d %d",&m,&n); tmp=n^m; while(tmp) { count++; tmp=tmp&(tmp-1); } printf("count=%d\n",count); system("pause"); return 0;
运行结果
#include<stdio.h> #include<stdlib.h> int main() { int m,n; int count=0; int tmp=0; printf("请输入两个任意整数:\n"); scanf("%d %d",&m,&n); tmp=n^m; while(tmp) { count++; tmp=tmp&(tmp-1); } printf("count=%d\n",count); system("pause"); return 0;
运行结果