9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia10/:w (463B)
   1 #include <stdio.h>
   2 
   3 int dot_product(int *v1, int *v2, size_t j);
   4 
   5 int main (void)
   6 {
   7     int v1[3] = { 1,2,3 };
   8     int v2[3] = { 1,2,3 };
   9     printf("%d\n", dot_product(v1,v2,3));
  10     return 0;
  11 }
  12 
  13 int dot_m(int *v1, int *v2, size_t index)
  14 {
  15     if(index == 0) return v1[0] * v2[0];
  16     return v1[index] * v2[index] + dot_product(v1, v2, index - 1);
  17 }
  18 
  19 int dot_product(int *v1, int *v2, size_t index)
  20 {
  21     return !index ? v1[0] * v2[0]: v1[l] * v2[l] + dot_product((v1, v2, l - 1);
  22 }