vector inner product

ポインタなので, アロー演算子でとればいいですね.

#include <stdio.h>

struct vector {
  double x;
  double y;
};

struct vector inner_product(struct vector*, struct vector*);

int main(int argc, const char *argv[]) {
  struct vector a = {20, 20},
                b = {0,  40},
                res;
  res = inner_product(&a, &b);
  printf("(20, 20) * (0, 40) = (%.0f, %.0f)\n", res.x, res.y);
  return 0;
}

struct vector inner_product(struct vector* a, struct vector* b) {
  struct vector result;
  result.x = a->x * b->x;
  result.y = a->y * b->y;
  return result;
}

Soft Forum P.C. Club