Compare commits
No commits in common. "6095c6fdf33482c67ee979ad6ccef5e5c008dff7" and "5118ea044e25cd6373882860148e38ae01be29a1" have entirely different histories.
6095c6fdf3
...
5118ea044e
32
vielmax.c
32
vielmax.c
@ -1,35 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
void vielmax(int x, ...){ //x gibt die Anzahl der eingelesenen Zahlen an //... sind die unbennanten Parameter
|
|
||||||
int zahl;
|
|
||||||
int vorgaenger = 0, max = 0; //Die Variablen werden benötigt, damit die Ausgabe der größten Zahl funktioniert.
|
|
||||||
|
|
||||||
va_list vielmax; //definiert die Variadische Funktion
|
|
||||||
va_start(vielmax, x); //übergibt die Anzahl an unbekannten Parametern
|
|
||||||
|
|
||||||
for (int i = 0; i < x; ++i) {
|
|
||||||
|
|
||||||
zahl = va_arg(vielmax,int); //Ließt durch die for-Schleife immer den nächsten Parameter ein
|
|
||||||
|
|
||||||
//Findet den größten wert heraus
|
|
||||||
if(zahl >= vorgaenger){
|
|
||||||
max = zahl;
|
|
||||||
}else if (zahl == 0){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d ", zahl);
|
|
||||||
vorgaenger = zahl;
|
|
||||||
}
|
|
||||||
printf("ist: %d", max);
|
|
||||||
va_end (vielmax); //Gibt den Speicher wieder frei
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
printf("Testprogramm fuer Funktion vielmax()\n");
|
printf("Praktikumsaufgabe");
|
||||||
printf("====================================\n\n");
|
|
||||||
printf("Das Maximum der Zahlen ");
|
|
||||||
|
|
||||||
vielmax(100, 24, 5226, 3243, 8238, 23, 22, 1, 0); //100 ist die maximale Anzahl der eingelesenen Zahlen
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user