In C++
1.) Create a function called copyMyArray. It should take in an array and copy array1 into array2.
2.) Create a vector and fill it with the numbers 1 to 10. Replace the number 3 with the number 3000. Insert the number 5000 between the 5 and 6.
#include <iostream>
using namespace std;
void copyMyArray(int array1[],int array2[],int n)
{
int i,j;
for(i=0;i<n;i++)//copy the values
{
array2[i]=array1[i];
}
}
int main()
{
int n;
cin>>n;//read how many numbers in array
int array1[n],array2[n];
int i,j;
for(i=0;i<n;i++)
{
cin>>array1[i];//read the values in the array
}
copyMyArray(array1,array2,n);//copy the function
for(i=0;i<n;i++)
cout<<array2[i]<<" ";
return 0;
}
2)
#include <iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v1;
for(int i=0;i<10;i++)
{
v1.push_back(i);//push the values
}
for (auto i = v1.begin(); i != v1.end(); ++i)
{
if(*i==3)//if the value is 3 update to 3000
{
*i=3000;
break;
}
}
v1.insert(v1.begin()+6,5000);//insert the value b/e 5 and 6
for (auto it : v1) //print the values
cout << it << " ";
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.