Pergunta de entrevista da empresa Apple

How do you count the number of 1's in a binary string?

Resposta da entrevista

Sigiloso

27 de abr. de 2017

#include // To execute C, please define "int main()" int main() { int input; printf("Enter the number in decimal:"); scanf("%d", &input); int count = 0; while(input != 0) { if(input & 0x01) { count++; } input = input >> 1; } printf("\n Entered number is %d\n", count); return 0; }