#include <stdio.h>
#include <stdlib.h>

struct Vector {
    int *data;      // 実データ
    size_t size;    // 使っている要素数
    size_t cap;     // 確保している容量
};

void vector_init(struct Vector *v) {
    v->size = 0;
    v->cap = 2;
    v->data = malloc(v->cap * sizeof *v->data);
}

void vector_free(struct Vector *v) {
    free(v->data);
}

int vector_push(struct Vector *v, int x) {
    if (v->size == v->cap) {
        size_t new_cap = v->cap * 2;
        int *tmp = realloc(v->data, new_cap * sizeof *v->data);
        if (!tmp) return 0;
        v->data = tmp;
        v->cap = new_cap;
    }
    v->data[v->size++] = x;
    return 1;
}

int main() {
    printf("Hello world!\n");
    struct Vector v;
    vector_init(&v);
    vector_push(&v, 1);
    vector_push(&v, 1);
    for (int i = 2; i < 16; i++) {
        vector_push(&v, v.data[i-1] + v.data[i-2]);
    }
    for (size_t i = 0; i < v.size; i++) {
        printf("%d ", v.data[i]);
    }
    return 0;
}


Embed on website

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