33 lines
628 B
C
33 lines
628 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "handle.h"
|
|
|
|
struct Vektor {
|
|
int count;
|
|
int *v;
|
|
}; handle(Vektor) {
|
|
if(HANDLE_CREAT == state) {
|
|
self->count = *(int*) data;
|
|
self->v = (int*) calloc(self->count, sizeof(int));
|
|
} else if (HANDLE_DESTR == state){
|
|
if(self->v) free(self->v);
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
int n;
|
|
printf("Number of elements to sum: ");
|
|
scanf(" %d", &n);
|
|
creat(Vektor, data, &n);
|
|
// printf("data.count:%d\n", data.count);
|
|
|
|
for(int i = 0; i < data.count; ++i) {
|
|
scanf(" %d", &n);
|
|
data.v[i] = n;
|
|
}
|
|
n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
|
|
printf("Sum: %d\n", n);
|
|
|
|
return 0;
|
|
}
|