Advertisement
Guest User

parzyste/nieparzyste

a guest
Mar 6th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int x = 0;
  9.     ifstream liczby;
  10.     liczby.open("liczby.txt");
  11.  
  12.     if(!liczby)
  13.     {
  14.         cout << "nie udalo sie otworzyc pliku";
  15.         getchar();
  16.         return 1;
  17.     }
  18.  
  19.     ofstream parzyste;
  20.     parzyste.open("parzyste.txt");
  21.  
  22.     if(!parzyste)
  23.     {
  24.         cout << "nie udalo sie otworzyc pliku";
  25.         getchar();
  26.         return 1;
  27.     }
  28.     ofstream nieparzyste;
  29.     nieparzyste.open("nieparzyste.txt");
  30.  
  31.     if(!nieparzyste)
  32.     {
  33.         cout << "nie udalo sie otworzyc pliku";
  34.         getchar();
  35.         return 1;
  36.     }
  37.  
  38.     while( liczby >> x)
  39.     {
  40.         if(x%2 == 0)
  41.             parzyste << x << endl;
  42.         else
  43.             nieparzyste << x << endl;
  44.     }
  45.  
  46.     liczby.close();
  47.     parzyste.close();
  48.     nieparzyste.close();
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement