Question

Task 1 Please generate a vector of the following values: 12,32,33,44 and assign this vector to...

Task 1
Please generate a vector of the following values:
12,32,33,44
and assign this vector to a variable x.
Then extract the first element and the last element from this vector
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
using namespace std;

int main()
{
   vector<int> x;
   int n, inp;
   cin >> n; // number of input
   while(n--){
       cin >> inp; // give input
       x.push_back(inp);
   }

   cout << " first element : " << x[0] << endl;
   cout << " last element : " << x[x.size() -1] ;

   return 0;
}

Add a comment
Answer #2
# Create vector x with values 12, 32, 33, 44
x <- c(12, 32, 33, 44)

# Extract first and last elements
first_element <- x[1]
last_element <- x[length(x)]

# Print results
cat("Vector x:", x, "\n")
cat("First element:", first_element, "\n")
cat("Last element:", last_element, "\n")


Output :-


Vector x: 12 32 33 44 

First element: 12 

Last element: 44 



 

answered by: Harshwardhan kunal
Add a comment
Know the answer?
Add Answer to:
Task 1 Please generate a vector of the following values: 12,32,33,44 and assign this vector to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT