質問

My Program doesnt work. I want to have the max and min values. Whats the mistake? Thx to all ;)

#include <stdio.h>
#include <stdlib.h>
#define N 5
int main()
{
    int wert[N],i,min,max;
    printf("Bitte geben Sie 5 Zahlen ein! \n");
    for(i=0;i<N;i++)
        scanf("%i",&wert[i]);//Eingabe der Werte
        printf("Wiederholung: \n");
    for(i=0;i<N;i++)
        printf("\n %i \n",wert[i]);//Aushabe der Werte
    for(i=0;i<N;i++)
        if (wert[i]<min)
        wert[i]=min;
        else if (wert[i]>max)
        wert[i]=max;
    printf("Maximalwert: %i",max);
    printf("Minimalwert: %i",min);
    return 0;
役に立ちましたか?

解決 2

min = max = wert[0];
for(i=1;i<N;i++)
        if (wert[i]<min)
        min = wert[i];//<--wert[i]=min;
        else if (wert[i]>max)
        max = wert[i];//<--wert[i]=max;

Apart from initialization, the values are assigned reverse

他のヒント

You did not initialise min, max.

#include <limits.h>

int min = INT_MAX;
int max = 0;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top