$ gcc -Wall -Werror multarraycopy.c
$ ./a.out
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
Last active
February 17, 2019 14:45
-
-
Save jboockmann/e2ffb6d821f71b2215bf0751618d09f5 to your computer and use it in GitHub Desktop.
multarraycopy.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int *multarraycopy(int scal, int *feld, int max) | |
{ | |
int *feldNeu = malloc(max * sizeof(int)); | |
for (int i = 0; i < max; i++) | |
{ | |
feldNeu[i] = feld[i] * scal; | |
} | |
return feldNeu; | |
} | |
int main(void) | |
{ | |
int feld[] = {1, 2, 3, 4, 5}; | |
int max = 5; | |
int scal = 2; | |
int *feldNeu = multarraycopy(scal, feld, max); | |
for (int i = 0; i < max; i++) | |
{ | |
printf("[%d] => %d\n", i, feldNeu[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo, ist das nicht zufälligerweise die Aufgabe?
"multarraycopy soll eine Zahl scal und ein Feld feld unter der Annahme, dass dieses im Hauptprogramm korrekt mit max Elementen angelegt und initialisiert wurde, als Eingabe nutzen, intern kopieren, alle Elemente mit dem Wert scal multiplizieren und als Ergebnis die geänderte Kopie zurückgeben ohne das Original zu verändern."