#include "stdafx.h"
#include <iostream>
using namespace std;
float getAverate(int *p,int allsInfo)
{
float num1=0;
for (int i=0;i<allsInfo;i++)
{
num1+=*(p+i);
//num1+=p[i];,原理是这样的,效果和上一致
}
return (float)num1/allsInfo;
}
void main()
{
int nums[8]={1,2,3,4,5,6,7,8};
cout<<getAverate(nums,8);
}
#include <iostream>
using namespace std;
float getAverate(int *p,int allsInfo)
{
float num1=0;
for (int i=0;i<allsInfo;i++)
{
num1+=*(p+i);
//num1+=p[i];,原理是这样的,效果和上一致
}
return (float)num1/allsInfo;
}
void main()
{
int nums[8]={1,2,3,4,5,6,7,8};
cout<<getAverate(nums,8);
}