daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Niklas Mueller
  2. // 3/27/2019
  3. // Computer Science
  4. //count number of 1s in n
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. int count(int number){
  11.   int ones;
  12.   while(number > 1){
  13.   if(number == 1){
  14.     ones = 1;
  15.   }
  16.   if(number == 0){
  17.     ones = 0;
  18.   }
  19.   //even
  20.   while((number % 2) == 0){
  21.     number / 2;
  22.   }
  23.   odd
  24.   if((number % 2) == 1) {
  25.     number - 1;
  26.     ones + 1;
  27.   }
  28.  
  29.   }
  30.   cout << ones << endl;
  31. };
  32.  
  33. count(0);
  34. count(13);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top