C++的array storage程式

2006-12-03 10:00 am
Use the array storage to store the input data(A,B and C points), and calculate the total side-length and area.
A(1,1,1)
B(-2,3,5)
C(1,7,2)

回答 (1)

2006-12-17 2:10 am
✔ 最佳答案
//Power by Microsoft Visual Studio 2005
//可以使用 Dev-C++ 編譯此程式
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(int argc,char **argv){
//=====START=====//
double SIDE_LENGTH(double *p1,double *p2);
double A[]={1,1,1},B[]={-2,3,5},C[]={1,7,2};
printf("Length of AB= %lf\n",SIDE_LENGTH(A,B));
printf("Length of BC= %lf\n",SIDE_LENGTH(B,C));
printf("Length of CA= %lf\n",SIDE_LENGTH(C,A));
//=====END=====//
system("PAUSE");
return EXIT_SUCCESS;
}//主程式
double SIDE_LENGTH(double *p1,double *p2){
double sideLEN;
int i;
for(i=0,sideLEN=0;i<3;i++){
sideLEN+=pow(p1[i]+p2[i],2);
}
return sqrt(sideLEN);
}
小綿羊忘了如何算三維面積……


收錄日期: 2021-04-27 17:13:22
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061203000012KK01309

檢視 Wayback Machine 備份