2025-04-25 01:50:15 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "array.h"
|
|
|
|
|
|
|
|
/* Prepare usage for 64 bit arrays - adds "Array_uint64" for creat */
|
|
|
|
Array(uint64_t, Array_uint64);
|
|
|
|
|
|
|
|
int main() {
|
2025-04-25 03:31:25 +02:00
|
|
|
size_t n = 0;
|
2025-04-25 01:50:15 +02:00
|
|
|
printf("Number of elements to sum: ");
|
2025-04-25 03:31:25 +02:00
|
|
|
scanf(" %zu", &n);
|
2025-04-25 21:44:24 +02:00
|
|
|
|
|
|
|
/* Create a 64 bit array of 'n' elements named 'data' */
|
2025-04-25 01:50:15 +02:00
|
|
|
creat(Array_uint64, data, &n);
|
|
|
|
|
|
|
|
for(int i = 0; i < data.count; ++i) {
|
2025-04-25 03:35:27 +02:00
|
|
|
scanf(" %zu", &n);
|
2025-04-25 01:50:15 +02:00
|
|
|
data.v[i] = n;
|
|
|
|
}
|
|
|
|
n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
2025-04-25 03:35:27 +02:00
|
|
|
printf("Sum: %zu\n", n);
|
2025-04-25 01:50:15 +02:00
|
|
|
|
|
|
|
// RAII releases array here automagicaly!
|
2025-04-25 21:44:24 +02:00
|
|
|
|
2025-04-25 01:50:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|