Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Create minmax.c
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdio.h> | ||
#include <float.h> | ||
|
||
int main() { | ||
int n; | ||
scanf("%d", &n); | ||
|
||
float f; | ||
float min, max; | ||
if (n == 0) { | ||
min = FLT_MAX; | ||
max = -FLT_MAX; | ||
} | ||
else { | ||
float listOfNum[n]; | ||
for (int i=0; i<n; i++) { | ||
scanf("%f", &f); | ||
listOfNum[i] = f; | ||
} | ||
min = listOfNum[0]; | ||
max = listOfNum[0]; | ||
for (int i =0; i<n; i++) { | ||
if (listOfNum[i] > max) { | ||
max = listOfNum[i]; | ||
} | ||
if (listOfNum[i] < min) { | ||
min = listOfNum[i]; | ||
} | ||
} | ||
} | ||
|
||
|
||
// DO NOT EDIT BELOW THIS LINE | ||
printf("The minimum value is: %.05f.\n", min); | ||
printf("The maximum value is: %.05f.\n", max); | ||
|
||
/* Let the OS know everything is just peachy. */ | ||
return 0; | ||
} |