ベクトル内積

#include <stdio.h>

double product(double a[],double b[]){
double ip;
int i;
ip=0;
for (i=0; i<3; i++) {
ip = ip + a[i]*b[i];
}
return ip;
}

int main() {
int i;
double a[3];
double b[3];
double x;
for (i=0; i<3; i++) {
printf("ベクトルaの第%d番目の要素を入力してください。",i+1);
scanf ("%lf",&a[i]);
}
for (i=0; i<3; i++) {
printf("ベクトルbの第%d番目の要素を入力してください。",i+1);
scanf ("%lf",&b[i]);
}
x=product(a,b);
printf("内積=%f\n", x);
return 0;
}

もどる

SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送