Created
October 20, 2016 14:28
-
-
Save dotWee/76463c051a417028fe68765d6d44bdb7 to your computer and use it in GitHub Desktop.
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
// | |
// Created by lukas on 19.10.2016. | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
// Anzahl der Argumente | |
// Bsp.: ./Getmax 1 5 3 7 9 | |
// -> Anzahl = 6, da wir aber nur die Zahlen wollen nur 5 | |
int len = argc-1; | |
// Feld mit der Länge = Anzahl der Zahlen als Argumente (5) | |
// Im Beispiel würde das Feld so aussehen: {1, 5, 3, 7, 9} | |
int zahlen[len]; | |
// Variable in der die größte Zahl geschrieben wird | |
int maximum = 0; | |
// Für jede Zahl die als Parameter angegeben wurde... | |
for(int i = 0; i < len; i++) { | |
// Schreibe die Zahl in das Feld zahlen | |
// atoi() -> Wandelt Zeichenkette in Zahl um | |
zahlen[i] = atoi(argv[i+1]); | |
} | |
// Bitte hier den Code zum Ermitteln des Maximums eingeben | |
// Für jede Zahl im Feld zahlen... | |
for (int j = 0; j < len; ++j) { | |
// Wenn die Zahl aus dem Feld zahlen größer oder gleich das letzte Maximum ist | |
if (zahlen[j] >= maximum) { | |
// Aktualisiere das Maximum | |
maximum = zahlen[j]; | |
} | |
} | |
// Gib das maximum in der Konsole/Terminal aus | |
printf("Maximum: %d\n", maximum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment