Δημοσιεύτηκε: 29 Νοέμ 2014, 12:45
από Star_Light
Spoiler: show
Κώδικας: Επιλογή όλων

#include<stdio.h>
int count_ones(unsigned char ch)
{
       unsigned int c;
       for( c = 0; ch; ch >>=1)
           c+= ch & 1; // 1 -> 0000001
      return c;
}
int main(void)
{
      unsigned char ch;
      printf("Enter a character: ");
      scanf(" %c", &ch);
      printf("Number of set bits (1) in %c is : " , ch , count_ones(ch));

      return 0;
}