撰写一个程序,从标准输入装置读取一串整数,并将读入的整数依次置入array及vector,然后遍历这两种容器,求取数值总和,将总和及平均值输出至标准输装置。
// 1_6.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
int a[5];
vector<int*> a_v(5);
int total=0,total_v=0;
//int* p;
//p=&a_v[0];
for(int i=0;i<5;i++)
{
cin >> a[i];
a_v[i]=&a[i];
}
for(int j=0;j<5;j++)
{
total += a[j];
total_v += *a_v[j];
}
/*for(int* p=&a_v[0];p<p+5;p++)
{
total_v+=*p;
}*/
cout << "total=" << total << endl;
cout << "average=" << total/5 << endl;
cout << "total_v=" << total_v << endl;
cout << "average=" << total_v/5 << endl;
system("pause");
return 0;
}