Advertisement
JosepRivaille

P27411: I-èssim (2)

Apr 6th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5.  
  6. //Pre: Legeix n i una seqüència de naturals x
  7. //Post: Escriu quina x hi ha a la posició n
  8. int main() {
  9.     vector <int> v;
  10.     int x;
  11.     cin >> x;
  12.     int n;
  13.     while (cin >> n and n != -1) v.push_back(n);
  14.     if (x < 1 or x > v.size()) cout << "Posicio incorrecta." << endl;
  15.     else cout << "A la posicio " << x << " hi ha un " << v[x - 1] << "." << endl;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement