40 lines
794 B
C
40 lines
794 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int* create_array(int size) {
|
|
int* array = (int*) malloc(size * sizeof(int));
|
|
return array;
|
|
}
|
|
|
|
void print_array(const int* array, int size) {
|
|
for (int i = 0; i < size; i++) {
|
|
printf("Element %d: %d\n", i, array[i]);
|
|
}
|
|
}
|
|
|
|
void free_array(int* array) {
|
|
free(array);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
int size;
|
|
|
|
printf("Geben Sie die Größe des Arrays ein: ");
|
|
scanf("%d", &size);
|
|
|
|
int* array = create_array(size);
|
|
|
|
printf("Geben Sie die Elemente des Arrays ein:\n");
|
|
for (int i = 0; i < size; i++) {
|
|
printf("Element %d: ", i);
|
|
scanf("%d", &array[i]);
|
|
}
|
|
|
|
printf("Das Array enthält folgende Elemente:\n");
|
|
print_array(array, size);
|
|
|
|
free_array(array);
|
|
|
|
return 0;
|
|
}
|