2025-04-25 01:45:51 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct Vektor {
|
|
|
|
int count;
|
|
|
|
int *v;
|
|
|
|
};
|
|
|
|
typedef struct Vektor Vektor;
|
|
|
|
|
|
|
|
Vektor create_Vektor(int count) {
|
|
|
|
Vektor self;
|
|
|
|
self.count = count;
|
|
|
|
self.v = (int*) calloc(self.count, sizeof(int));
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2025-04-25 21:44:24 +02:00
|
|
|
int sum_Vektor(Vektor *self) {
|
|
|
|
int s = 0;
|
|
|
|
for(int i = 0; i < self->count; ++i) {
|
|
|
|
s += self->v[i];
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2025-04-25 01:45:51 +02:00
|
|
|
void delete_Vektor(Vektor *self) {
|
|
|
|
if(self->v) free(self->v);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int n;
|
|
|
|
printf("Number of elements to sum: ");
|
|
|
|
scanf(" %d", &n);
|
|
|
|
Vektor data = create_Vektor(n);
|
|
|
|
// printf("vektor.count:%d\n", data.count);
|
|
|
|
|
|
|
|
for(int i = 0; i < data.count; ++i) {
|
|
|
|
scanf(" %d", &n);
|
|
|
|
data.v[i] = n;
|
|
|
|
}
|
2025-04-25 21:44:24 +02:00
|
|
|
// n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
|
|
|
n = sum_Vektor(&data);
|
2025-04-25 01:45:51 +02:00
|
|
|
printf("Sum: %d\n", n);
|
|
|
|
|
|
|
|
// Need to not forget this
|
|
|
|
delete_Vektor(&data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|