Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int n, Z = 0, U = 0;
  8.  
  9. cin >> n;
  10. while (n != 0) {
  11. if (n % 2 == 1)
  12. U++;
  13. else if (n % 2 == 0)
  14. Z++;
  15. n = n / 2;
  16. }
  17. cout << Z << " " << U << endl;
  18. return 0;
  19.  
  20. }
  21. /* Explicatie
  22. Il impartim pe n la 2 pana devine 0, cat timp nu e 0 vedem daca cand se imparte la 2 se imparte cu rest. Restul poate sa fie 0 sau 1, daca se imparte cu restul 0 inseamna ca avem un bit de 0 iar daca se imparte cu restul 1 inseamna ca avem un bit de 1. U reprezinta numarul de biti de unu, si Z numarul de biti de 0.
  23. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement