1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> #include <stdlib.h> //Napisz program, który dla danej liczby n obliczy ile jej bitów jest równe 1. int main(int argc, char *argv[]) { printf ("Podaj n: "); unsigned int n; scanf ("%d",&n); int zlicz = 0; while (n>0) { if (n%2 == 1) { zlicz++; } n=n/2; } unsigned wyj; wyj=zlicz; printf ("\n%d\n\n",wyj); system("PAUSE"); return 0; } |