Originally Posted by
Kernelpanic
An idea, take the input numbers through two (first(x) - last(x)) and sort the last part for maximum and minimum, and then add this two numbers.
Reset your brain!
Ok, I have reset my brain and this is the idea as a program (English version, almost):
Code:
//Aus der 2ten Hälfe von Nummern die niedrigste und die höchste
//herausfinden und addieren - 6./7. Dez. 2018
//From the 2nd half of numbers the lowest and the highest
//find out and add
#include <stdio.h>
#include <stdlib.h>
#define MAX 20
int maximum_aus_feld(int *eingabe, int groesse);
int minimum_aus_feld(int *eingabe, int groesse);
int main(void)
{
//The right field is to browsed
int eingabe_feld[MAX];
int rechtes_feld[MAX / 2];
int *feld_eingabe_zgr = &eingabe_feld[0];
int *feld_rechts_zgr = &rechtes_feld[0];
int anzahl, eingabe;
int rechte_haelfte;
printf("\nWie viele Zahlen eingeben?: ");
scanf("%d", &anzahl);
//Eingaben 0 bis über MAX abfangen
if (anzahl == 0)
{
printf("\nFalsche Eingabe!\n");
exit(0);
}
else if (anzahl > MAX)
{
printf("\nMaximum sind 20 Zahlen!\n");
exit(0);
}
else
{
for (int i = 0, j = 1; i < anzahl; i++)
{
printf("Nummer:%2d = ", j++);
scanf("%3d", &eingabe);
eingabe_feld[i] = eingabe;
if (anzahl == 1)
{
printf("\nOrder number = %2d", eingabe_feld[i]);
exit(0);
}
else continue;
}
}
//And catch(?) 2 + 3
if (anzahl == 2)
{
int i = 0;
printf("\nOrder number = %2d", eingabe_feld[i + 1]);
exit(0);
}
else if (anzahl == 3)
{
printf("\nOrder number = %2d", (eingabe_feld[1] + eingabe_feld[2]));
exit(0);
}
printf("\nIhre Eingabe war: ");
for (int i = 0; i < anzahl;)
{
printf("%3d", feld_eingabe_zgr[i++]);
}
//Hälfte der Anzahl, odd or even input quantity
if (anzahl % 2 == 0)
{
rechte_haelfte = anzahl / 2;
}
else
{
rechte_haelfte = ((anzahl / 2) + 1);
}
//Without "größer gleich: >=" error with odd input numbers (quantity)
for (int i = anzahl, j = 1, z = 0; i >= rechte_haelfte; i--, j++, z++)
{
rechtes_feld[z] = eingabe_feld[anzahl - j];
}
//Ordnung muß sein! ;)
printf("\nOrder number = %3d", (maximum_aus_feld(feld_rechts_zgr, rechte_haelfte)
+ minimum_aus_feld(feld_rechts_zgr, rechte_haelfte)));
printf("\n");
return(0);
}
int maximum_aus_feld(int *eingabe, int groesse)
{
//Auf Anfang setzen - Put to the beginning
int maximum = eingabe[0], i;
for(i = 1; i < groesse; i++)
{
//If "eingabe[]"(Input) greater than maximum is eingabe[]
if(eingabe[i] > maximum)
{
maximum = eingabe[i];
}
}
return maximum;
}
int minimum_aus_feld(int *eingabe, int groesse)
{
int minimum = eingabe[0], i;
for(i = 1; i < groesse; i++)
{
//The same like maximum only "<"
if(eingabe[i] < minimum)
{
minimum = eingabe[i];
}
}
return minimum;
}
Output examples: