michael_hartman_cz

PA1 test z 23. 11. 2011 od 14:30 - Test IIIa

Jan 2nd, 2013
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ( int argc, char * argv[] )
  5.  {
  6.   cout << "Zadejte n:" << endl;
  7.   int n;
  8.   cin >> n;
  9.   if ( cin.fail() || n <= 0 )
  10.    {
  11.     cout << "Nespravny vstup" << endl;
  12.     return 1;
  13.    }
  14.  
  15.   cout << "Zadejte cisla" << endl;
  16.   int  c = 0, tmp;
  17.   bool progress = false;
  18.   for ( ; n != 0; n-- )
  19.    {
  20.     cin >> tmp;
  21.     if ( cin.fail() )
  22.      {
  23.       cout << "Nespravny vstup" << endl;
  24.       return 1;
  25.      }
  26.     if ( !progress )
  27.      {
  28.       if ( tmp % 2 == 0 )
  29.        {
  30.         c++;
  31.         progress = true;
  32.        }
  33.      }
  34.     else
  35.      {
  36.       if ( tmp % 2 != 0 )
  37.        progress = false;
  38.      }
  39.    }
  40.   cout << "Vysledek: " << c << endl;
  41.   return 0;
  42.  }
Advertisement
Add Comment
Please, Sign In to add comment