Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void count1s0s(int N)
- {
- int count0 = 0, count1 = 0;
- while (N > 0) {
- // ako tek bit e 1
- if (N & 1) {
- count1++;
- }
- // ako tek bit e 0
- else {
- count0++;
- }
- N = N >> 1;
- }
- printf("Count of 0s in N is %d\n", count0);
- printf("Count of 1s in N is %d\n", count1);
- }
- int main()
- {
- // zadadeno chislo
- int N = 10;
- // izvikva funkciata
- count1s0s(N);
- return 0;
- }
Add Comment
Please, Sign In to add comment