TASK 1: [20]
• Write a little program that creates a vector array of type doubles with 10 members (0…9)
• Use a for loop to store the values i^2 in the vector for each index i
• Also write code to display the content of the vector
• The output should be: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81
• Instead of using array access, try to use push_back, pop_back, etc. also, i.e. try being dynamic.
TASK 2: [20]
• Generate random numbers between -1.0 and 1.0
• Store these numbers in a vector
• Play a bit with random and show us what you did
Q1)
c++ code:
#include <bits/stdc++.h> using namespace std; int main() { vector<double>v; //push_back element in vector for(int i=0;i<10;i++) { v.push_back(i*i); } cout<<"Element of vector are:"; for(int i=0;i<10;i++) { cout<<v[i]<<" "; } return 0; }
c++ code screenshot::
TASK 1: [20] • Write a little program that creates a vector array of type doubles with 10 members (0…9) • Use a for loop to store the values i^2 in the vector for each index i • Also write code to display the content of the vector • The output shou