![]() |
/* Example maxloop.c Running Max |
![]() |
Goal: The use of if statement inside the loop |
![]() |
Author: Peter Brusilovsky |
![]() |
Reads numbers until -1 is entered. Prints the max number entered. |
| The semantic interpretation of this program is funding out the size of the largest group coming to the party. | |
![]() |
*/ |
![]() |
|
![]() |
#define SENTINEL -1 |
![]() |
#include <stdio.h> |
![]() |
|
![]() |
void main () { |
![]() |
int max, nextnumber; |
![]() |
|
![]() |
printf("Number: "); |
![]() |
scanf("%d", &nextnumber); /* read first number */ |
![]() |
max = nextnumber; /* pre-assignment */ |
![]() |
|
![]() |
while (nextnumber != SENTINEL) { |
![]() |
if (max < nextnumber) |
![]() |
max = nextnumber; |
![]() |
printf("Number: "); |
![]() |
scanf("%d", &nextnumber); |
![]() |
} |
![]() |
printf ("Max = %d ", max); |
![]() |
} |