Struct – Vector2
Description:
給定一個名為Vector2的struct,如下列所示:
Vector2
- int x
- int y
再給定主要執行程式main.c (題號.c)、以及Header檔function.h (題號.h);請試著完成Header檔中未實現的函式:SetValue()、Add()、Sub()、Mul()、Div()
Methods:
- void SetValue(Vector2 *v1, double _x, double _y) - Should set v1’s x value to _x, v1's y value to _y
- Vector2 Add(Vector2 v1, Vector2 v2) - Should return a Vector2 which is addition of v1 and v2
- Vector2 Sub(Vector2 v1, Vector2 v2) - Should return a Vector2 which is subtraction of v1 and v2
- Vector2 Mul(Vector2 v1, double d) - Should return a Vector2 which is multiplication of v1 and d
- Vector2 Div(Vector2 v1, double d)) - Should return a Vector2 which is division of v1 and d
function.c
輸入符合以下格式
op
x1 y1
(x2 y2 or d)
Note:
輸出符合以下格式:
(x, y)
Note: