#include <iostream>
#include <string>
#include <cmath>
using namespace std;

struct Student{ //암묵적으로 구조체 이름은 대문자로 시작. 구조체는 메인 위에서 선언
    string name;
    int age;
    double score;
}; //구조체 뒤에는 ; 붙여야 함

struct Vector{
    double x;
    double y;
};

Vector add(Vector a, Vector b){
    Vector result;
    
    result.x = a.x + b.x;
    result.y = a.y + b.y;
    
    return result;
}

double dot(Vector a, Vector b){ 

    return a.x * b.x + a.y * b.y;
}

double magnitude(Vector a){ 

    return sqrt(a.x * a.x + a.y * a.y);
}

int main() {
    /*Student s1;
    s1.name = "Gyurim";
    s1.age = 20;
    s1.score = 0;

    Student s2 = {"Gyurim", 20, 0}; //선언한 순서대로 써야함
*/
    Vector v1;
    Vector v2;

    cin >> v1.x >> v1.y;
    cin >> v2.x >> v2.y;

    Vector s = add(v1, v2);
    cout << "벡터 덧셈 결과: (" << s.x << "," << s.y << ")\n";

    double d = dot(v1, v2);
    cout << "벡터 내적 결과: " << d << "\n";

    double v1_size = magnitude(v1);
    double v2_size = magnitude(v2);
    cout << "v1의 크기: " << v1_size << "\n";
    cout << "v2의 크기: " << v2_size << "\n";
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: