Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. /**
  2.     Saisir les valeurs d'un tableau de taille n, on utilise la mémoire (pointeur)
  3.     Un pointeur est une variable qui contient l'adresse d'une autre variable.
  4. */
  5. int *EcrireTableau(int n)
  6. {
  7.     int *t = new int[n];
  8.     int i;
  9.     for(i=0; i<n;i++)
  10.     {
  11.         cout << "Saisir t[" << i <<"] = "<<endl;
  12.         cin >> t[i];
  13.     }
  14.     return t;
  15. }
  16.  
  17. int main()
  18. {
  19.     int n;
  20.     int x;
  21.     bool res;
  22.  
  23.     cout << "Saisir la taille du tableau :" << endl;
  24.     cin >> n;
  25.     int *t1 = EcrireTableau(n);
  26.     AfficheTableau(t1,n);
  27.  
  28.     cout << "Saisir un nombre : " << endl;
  29.     cin >> x;
  30.     res = AppartTableau(t1,n,x);
  31.     if(res)
  32.         cout << x << " appartient au tableau " << endl;
  33.     else
  34.         cout << x << " n'appartient pas au tableau" << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement