fork download
  1. #include <iostream>
  2. using namespace std;
  3. // array monodimensionali;
  4. // 1) definizione e caricamento
  5. //2) stampa
  6. //3) ricerca sequenziale del primo vettore
  7. int V[10];
  8. int i;
  9. int main() {
  10. //caricamento
  11. for (i=0; i<10; i++)
  12. cin>>V[i];
  13. //stampa
  14. for (i=0; i<10; i++)
  15. cout<<V[i]<<"\t";
  16.  
  17. //ricerca sequenziale
  18. int count=0;
  19. for (i=0; i<10; i++)
  20. if(V[i]==V[0]){count++;}
  21. cout<<endl<<V[0]<<" è presente "<<count<<" nel vettore"<<endl;
  22. //ricerca sequenziale
  23. count=0;
  24. for (i=0; i<10; i++)
  25. if(V[i]==V[9]){count++;}
  26. cout<<endl<<V[9]<<" è presente "<<count<<" nel vettore"<<endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5280KB
stdin
0
0
3
1
3
1
3
13
1
3
1
9
stdout
0	0	3	1	3	1	3	13	1	3	
0 è presente  2 nel vettore

3 è presente  4 nel vettore