- #include<iostream>
- #include<vector>
- using namespace std;
- int main()
- {
- vector<float> v;//存放float
- float f;
- for(int i=0;i<5;i++)
- {
- cin>>f;
- v.push_back(f);
- cout<<v[i]<<endl;
- }
- return 1;
- }
- #include<iostream>
- #include<vector>
- using namespace std;
- int main()//求平方,写得极丑。。。
- {
- vector<float> v;
- float f;
- cout<<"input 3 elements:"<<endl;
- for(int i=0;i<3;i++)
- {
- cin>>f;
- v.push_back(f);
- }
- cout<<"before:"<<endl;
- for(i=0;i<3;i++)
- {
- cout<<v[i]<<endl;
- v[i]=v[i]*v[i];
- }
- cout<<"after:"<<endl;
- for(i=0;i<3;i++)
- cout<<v[i]<<endl;
- return 1;
- }
- #include<iostream>
- #include<vector>
- using namespace std;
- int main()
- {
- vector<float> v;//求和
- float f;
- for(int i=0;i<2;i++)
- {
- cin>>f;
- v.push_back(f);
- }
- v.resize(3);
- v[2]=v[1]+v[0];
- cout<<v[2]<<endl;
- return 1;
- }