想使用文件读取 怎么弄?
#include<iostream>#include<cmath>
#include<fstream>
using namespace std;
int main()
{
int i;
int n;
double temp=0,mean,variance,stddeviation;
double sum=0;
double j=0;
cout<<"请输入数字:";
cin>>n;
double *array=new double[n];
for(i=0;i<n;i++)
{
cin>>temp;
sum=sum+temp;
*(array+i)=temp;
}
mean=sum/n;
for(i=0;i<n;i++){
j=j+(array[i]-mean)*(array[i]-mean);
}
variance=j/(n-1);
stddeviation=sqrt(variance);
cout<<"mean="<<mean<<endl;
cout<<"variance="<<variance<<endl;
cout<<"stddeviation="<<stddeviation<<endl;
cin.get();
cin.get();
return 0;
}
谢谢啦