可是这是我们老师给的期末作业题目啊,应该没错吧......我现在做了个这个程序,要输入想取得的小四面体的个数,再取其平均值,但是我总觉得不对。。。
#include <conio.h>
#include<stdlib.h>
#include<time.h>
#include <iostream>
#include <math.h>
using namespace std;
double main()
{
while(1)
{double v=0;
int m;
int n;
cout<<"请输入想要取的小四面体个数:"<<endl;
cin>>n;
cout<<n<<"个小四面体"<<endl;
srand((unsigned)time(NULL));
int i=0;
double N[4][3];
double k;
for (m=0;m<n;m++)
{do
{double a=fabs((rand()%1000)*0.001),b=fabs((rand()%1000)*0.001),c=fabs((rand()%1000)*0.001);
k=a+b+c-1;
if(k<0)
{N[i][0]=a;
N[i][1]=b;
N[i][2]=c;
i++;}
}while(i<4);
if(i=4){double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,A1,A2,A3,A4;
x1=N[0][0];y1=N[0][1];z1=N[0][2];
x2=N[1][0];y2=N[1][1];z2=N[1][2];
x3=N[2][0];y3=N[2][1];z3=N[2][2];
x4=N[3][0];y4=N[3][1];z4=N[3][2];
A1=x2*(y3*z4-y4*z3)-x3*(y2*z4-y4*z2)+x4*(y2*z3-y3*z2);
A2=x1*(y3*z4-y4*z3)-x3*(y1*z4-y4*z1)+x4*(y1*z3-y3*z1);
A3=x1*(y2*z4-y4*z2)-x2*(y1*z4-y4*z1)+x4*(y1*z2-y2*z1);
A4=x1*(y2*z3-y3*z2)-x2*(y1*z3-y3*z1)+x3*(y1*z2-y2*z1);
v=fabs((A2-A1+A4-A3)/6);
v+=v;
i=0;
}
}
double E;
E=v/n;
cout<<"E="<<E<<endl;
cout<<endl;
}
return 0;
}