Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdexcept>
- #include <vector>
- using namespace std;
- vector<double> Vektorcici (vector<double> A, vector<int> B)
- {
- vector<double> C(0);
- for (int i=0; i<B.size(); i++) {
- if (B[i]>A.size()) throw range_error ("Greska.");
- }
- for (int i=0; i<B.size(); i++) {
- C.push_back(A[B[i]]);
- }
- return C;
- }
- int main () {
- vector<double> A{1,6,3,9,45,2,5,7};
- vector<int> B{3,5,2,0,5};
- try {
- vector<double> C{Vektorcici(A,B)};
- for (auto x: C) cout<<x<<" ";
- }
- catch(const char poruka[]) {
- cout<<poruka;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement