#include <stdio.h>
void normal(double *a, double *b, int n);
double mag(double *a, int n);
void print_vector(double *a, int n);
int main()
{
double a[] = {1.1, 2.0, 3.5};
double b[3];
int n;
n = sizeof(a)/sizeof(a[0]);
printf("ベクトルaの要素数は%dです。\n", n
);
print_vector(a, n);
printf("ベクトルaの大きさは%lfです。\n", mag
(a
, n
));
printf("ベクトルaを大きさ1に規格化した成分は\n"); normal(a, b, n);
print_vector(b, n);
printf("ベクトルbの大きさは%lfです。\n", mag
(b
, n
));
return 0;
}
void normal(double *a, double *b, int n)
{
double v;
int i;
v = mag(a, n);
for (i = 0; i < n; i++) {
b[i] = a[i] / v;
}
}
double mag(double *a, int n)
{
double v = 0.0;
int i;
for (i = 0; i < n; i++) {
v += a[i] * a[i];
}
}
void print_vector(double *a, int n)
{
int i;
for(i = 0; i < n; ++i)
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIG5vcm1hbChkb3VibGUgKmEsIGRvdWJsZSAqYiwgaW50IG4pOwpkb3VibGUgbWFnKGRvdWJsZSAqYSwgaW50IG4pOwp2b2lkIHByaW50X3ZlY3Rvcihkb3VibGUgKmEsIGludCBuKTsKCmludCBtYWluKCkKewoJZG91YmxlIGFbXSA9IHsxLjEsIDIuMCwgMy41fTsKCWRvdWJsZSBiWzNdOwoJaW50IG47CgoJbiA9IHNpemVvZihhKS9zaXplb2YoYVswXSk7CglwcmludGYoIuODmeOCr+ODiOODq2Hjga7opoHntKDmlbDjga8lZOOBp+OBmeOAglxuIiwgbik7CgoJcHJpbnRmKCLjg5njgq/jg4jjg6th44Gu5oiQ5YiG44GvXG4iKTsKCXByaW50X3ZlY3RvcihhLCBuKTsKCglwcmludGYoIuODmeOCr+ODiOODq2Hjga7lpKfjgY3jgZXjga8lbGbjgafjgZnjgIJcbiIsIG1hZyhhLCBuKSk7CgoJcHJpbnRmKCLjg5njgq/jg4jjg6th44KS5aSn44GN44GVMeOBq+imj+agvOWMluOBl+OBn+aIkOWIhuOBr1xuIik7C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