fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct _vector_2d {
  5. float x, y;
  6. } vector2;
  7.  
  8. int main() {
  9. vector2 a = { 2, 3 };
  10. vector2 b = { 4, 5 };
  11.  
  12. printf("Vector A: (%.2f, %.2f)\n", a.x, a.y);
  13. printf("Vector B: (%.2f, %.2f)\n", b.x, b.y);
  14. printf("CosΘ: %.2f\n", (a.x*b.x+a.y*b.y)/(sqrt(a.x*a.x+a.y+a.y)*sqrt(b.x*b.x+b.y*b.y)));
  15. }
Runtime error #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
Vector A: (2.00, 3.00)
Vector B: (4.00, 5.00)
CosΘ: 1.14