Segmentation fault of hikko624 「help me」

  • 2013/6/14 0:15
  • タグ:
  • タグはありません
#include <stdio.h>
#include <stdlib.h>
#define BUSI 256
#define N 2

int main(void)
{
  char buf[BUSI];
  int u[N];
  int v[N];
  int i,sum;
  for(i=0 ; i < N ; i++) {
    printf("input u[%d]",i);
    fgets(buf,BUSI,stdin);
    u[i] = atoi(buf);
    }
  
  for(i=0 ; i < N ; i++) {
    printf("input v[%d]",i);
    fgets(buf,BUSI,stdin);
    v[i] = atoi(buf);
  }
  printf("u=[");
  for(i=0 ; i < N ; i++) {
    printf("%2d",u[i]);
  }
  printf(" ], ");
  printf("v=[");
  for(i=0 ; i < N ; i++) {
    printf("%2d",v[i]);
  }
  printf(" ]\n");
  
  sum = 0;
  sum = innerProduct(u[N],v[N]);
  
  printf("inner product is %d",sum);
   if(sum>0){
	    printf("The angle of the vectors is less than 90 degree.");
    }else if(sum==0){
        printf("The angle of the vectors is  90 degree.");
    }else{
        printf("The angle of the vectors is greater than 90 degree.");
    }
    printf("\n"); 
    return 0;
}

int innerProduct(int u[],int v[])
{
  int i,total;
  total = 0;
  for(i=0 ; i < N ; i++) {
    total += u[i]*v[i];
  }
  return total;
}