ToniDev

S2-EX1-D) - Sub. Teza 2

May 23rd, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 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.     cin >> n; // n = 4
  10.  
  11.     /*
  12.       Singura diferenta este la FOR
  13.  
  14.       Nu am mai folosit while (n > 0)
  15.  
  16.     */
  17.    
  18.     for(int i = n; n > 0; i--){
  19.         cout << "Introdu x: ";
  20.         cin >> x;
  21.        
  22.         while(x % 2 == 0)
  23.             x = x / 2;
  24.        
  25.         if(x == 1)
  26.             y = y + 1;
  27.     }
  28.    
  29.     cout << "Y = " << y;
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment