Advertisement
Guest User

Untitled

a guest
May 9th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int dim_a = 7;
  6.  
  7. bool array(int a[], int dim_a, int x, int l)
  8. {
  9.     int contatore = 1;
  10.     bool trovato = false;
  11.  
  12.         while(trovato == false)
  13.         {
  14.             for(int i = 0; i < dim_a; i++)
  15.             {
  16.                 if(a[i] == a[i+1])
  17.                 contatore++;
  18.                     if(contatore == l)
  19.                     {
  20.                         trovato = true;
  21.                         cout <<"Trovato.\n";
  22.                         return trovato;
  23.                     }
  24.  
  25.             }
  26.         }
  27.  
  28. if(trovato == false)
  29. cout <<"Non c'è.\n";
  30. return trovato;
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36.  
  37. int a[dim_a] = {6,4,3,3,2,7,9};
  38. int x;
  39. int l;
  40. cout <<"Inserire il numero da cercare.\n";
  41. cin >> x;
  42. cout <<"Quante volte consecutive vuoi cercarlo?\n";
  43. cin >> l;
  44.  
  45. array(a,dim_a,x,l);
  46.  
  47. return 0;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement