SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- int summe(int[] feld) {
- // Wenn das Feld nur noch ein Element hat, wird das zurückgegeben und die Funktion dann abgebrochen
- if (feld.length == 1) {
- return feld[0];
- }
- // Array teilen
- int[] f1 = new int[feld.length/2];
- int[] f2 = new int[ceil((float)feld.length/2.0)];
- for (int i = 0; i < feld.length; i++) {
- if (i < feld.length/2) {
- f1[i] = feld[i];
- }
- else {
- f2[i-feld.length/2] = feld[i];
- }
- }
- // Geteiltes Array der Funktion wieder übergeben
- return summe(f1)+summe(f2);
- }
- // Die Rechnung starten
- void setup() {
- int[] feld = {1, 2, 4, 5, 7, 9, 2, 4, 6};
- print(summe(feld));
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.