vendredi 28 décembre 2018

Print biggest and smallest numbers ,until -1 is given

It works, but if you don't enter any number smaller than 0 it doesn't print the smaller value and prints 0.

int max = 0;
int min = 0;
int a;

printf("Enter a number:\n");
scanf("%d", &a);

while (a != -1){
        if (a < min){
            min = a;
        }

        if (a > max){
            max = a;
        }
        scanf("%d", &a);
}
printf("Your largest number is %d. Your smallest number is %d.", max, min);

Aucun commentaire:

Enregistrer un commentaire