// PROGRAM vector // 配列の表示 #include "TrueBASIC.h" int main(); void initial(double a[], double b[]); void dot(double a[], double b[]); void cross(double r[], double s[]); int main() { double a[4], b[4]; initial(a, b); dot(a, b); cross(a, b); return 0; } void initial(double a[], double b[]) { a[1] = 2; a[2] = -3; a[3] = -4; b[1] = 6; b[2] = 5; b[3] = 1; } void dot(double a[], double b[]) { int i; double dot_product; dot_product = 0; for(i = 1; i <= 3; ++i) { dot_product += a[i]*b[i]; } printf("scalar product = %f\n", dot_product); } void cross(double r[], double s[]) // 配列は主プログラムやサブルーチンの中でも定義できる // 仮の変数を用いていることに注意 { int component, i, j; double cross_product[4]; for(component = 1; component <= 3; ++component) { i = (component % 3) + 1; j = (i % 3) + 1; cross_product[component] = r[i]*s[j] - s[i]*r[j]; } printf("\n"); printf("three components of the vector product:\n"); printf(" x y z \n"); for(component = 1; component <= 3; ++component) printf("%12f ", cross_product[component]); }