[ create a new paste ] login | about

Link: http://codepad.org/9VxeccBK    [ raw code | output | fork ]

C, pasted on Jul 14:
#include <stdio.h>
#define N 3
int main() {
  int u[N], v[N];
  int i, p;
  for (i = 0; i < N; i++) {
    printf("input u[%d]: ", i);
    scanf("%d", &u[i]);
  }
  for (i = 0; i < N; i++) {
    printf("input v[%d]: ", i);
    scanf("%d", &v[i]);
  }
  printf("u = [ ");
  for (i = 0; i < N; i++)
    printf("%d ", u[i]);
  printf("]\n");

  printf("v = [ ");
  for (i = 0; i < N; i++)
    printf("%d ", v[i]);
  printf("]\n");
  
  p = 0;
  for (i = 0; i < N; i++)
    p += u[i] * v[i];
  printf("inner product is %d\n", p);
  printf("The angle of the vectors is %s\n",
         (p > 0) ? "less than 90 degrees." :
         (p < 0) ? "more than 90 degrees." : "just 90 degrees");
  return 0;
}
/* end */


Output:
1
2
3
4
input u[0]: input u[1]: input u[2]: input v[0]: input v[1]: input v[2]: u = [ 134513774 134514288 0 ]
v = [ -1081812144 1073784948 1073830340 ]
inner product is 1404167968
The angle of the vectors is less than 90 degrees.


Create a new paste based on this one


Comments: