Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX 1000
- #include <stdio.h>
- int conta(int n){ //restituisce il numero di cifre 1 presenti in n rappresentato in base 2
- int t = 0;
- while (n>0) {
- if(n%2) t++;
- n = n/2;
- }
- return t;
- }
- int main() {
- int i,t = 0;
- for(i=0;i<=MAX;i++) t+= conta(i);
- printf("Tot: %d\n",t);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement