ToniDev

S2-EX1-C) - Sub. Teza 2

May 23rd, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.    
  6.     int n, y, x;
  7.    
  8.     y = 0;
  9.     cout << "n = ";
  10.     cin >> n;
  11.  
  12.     while(n > 0){
  13.         cout << "Introdu x: ";
  14.         cin >> x;
  15.        
  16.         while(x % 2 == 0)
  17.             x = x / 2;
  18.        
  19.         if(x == 1)
  20.             y = y + 1;
  21.        
  22.         n = n - 1;
  23.     }
  24.    
  25.     cout << "Y = " << y;
  26.    
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment