Advertisement
rootuss

ile zer

Dec 2nd, 2017
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   //  int a,b,c,d,e, n=0;
  10.     int licznik=0, licznik_wszystkie=0;
  11.     int dl, i=0,x=1;
  12.     string ciag,linia;
  13.     fstream plik;
  14.     plik.open("dane.txt", ios::in);
  15.  
  16.     if(plik.good()==false) cout<<"Nie mozna otworzyc pliku!";
  17.  
  18.     while (!plik.eof())
  19.     {
  20.            while (getline(plik, linia))
  21.          {
  22.              ciag=linia;
  23.              cout<<ciag;
  24.              //cout<<ciag[0];
  25.              //cout<<ciag[1];
  26.              cout<<endl;
  27.              dl=ciag.length();
  28.              //cout<<dl;
  29.              while(i<dl)
  30.              {
  31.                 if(ciag[i]=='0') {licznik++;}
  32.                 i++;
  33.              }
  34.              cout<<"Zer w "<<x<<" wierszu jest: "<<licznik<<endl<<endl;
  35.              licznik_wszystkie+=licznik;
  36.              licznik=0;
  37.             i=0;
  38.             x++;
  39.          }
  40.     }
  41.     cout<<endl;
  42.     cout<<"Razem wystapilo zer: " <<licznik_wszystkie<<endl;
  43.  
  44.     plik.close();
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement