#include "stdafx.h"
#include <stdio.h>

#include "t7.h"


int CountOf1(int num)
{
	int count = 0 ;

	while(num > 0){
		if(num & 1 != 0 ){
			count++;
		}
		num >>= 1;
	}
	return count;
}


int t7(void)
{
	printf("CountOf1(4) = %d\n", CountOf1(4));
	printf("CountOf1(124) = %d\n", CountOf1(124));
	printf("CountOf1(1234) = %d\n", CountOf1(1234));
	printf("CountOf1(4123) = %d\n", CountOf1(4123));

	return 0;
}
/*
CountOf1(4) = 1
CountOf1(124) = 5
CountOf1(1234) = 5
CountOf1(4123) = 5
Press any key to continue . . .
*/

 

相关文章:

  • 2022-02-23
  • 2021-11-28
  • 2022-12-23
  • 2022-03-15
  • 2021-05-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2021-08-31
  • 2021-09-11
相关资源
相似解决方案