SHARE
TWEET

Untitled

a guest May 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include  <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cout << "quanti numeri vuoi inserire?";
  11.     cin >> n;
  12.    
  13.     ofstream fout("numeri.txt");
  14.     if(fout){
  15.         for(int i =0; i<n; i++){
  16.         int h;
  17.         cout << "inserisci numero ";
  18.         cin >> h;
  19.         fout << h;
  20.         }
  21.        
  22.        
  23.     }
  24.     fout.close();
  25.    
  26.     int ns;
  27.    
  28.     cout << "di quale numero vuoi contare le occorrenze? ";
  29.     cin >> ns;
  30.     ifstream fin("numeri.txt");
  31.     if(fin){
  32.         int nOccorrenze=0;
  33.         while(!fin.eof()){
  34.             int a;
  35.             fin >> a;
  36.             cout << (a==1);
  37.             if(a == ns){
  38.                 nOccorrenze++;
  39.                 cout << "ano";
  40.             }
  41.         }
  42.         cout << "sono state contate " << nOccorrenze << " occorrenze di " << ns;
  43.     }
  44.     fin.close();
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top