Last active
September 16, 2016 15:07
-
-
Save ohmree/4a58923cf4ece81afd735adde14ea2bf to your computer and use it in GitHub Desktop.
Functions that find the biggest/smallest number from an arbitrary number of arguments
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
#include <stdarg.h> | |
int maxOf(int num, ...) | |
{ | |
va_list args; | |
int max; | |
register int i; | |
va_start(args, num); | |
for (i = 0; i < num; i++) | |
{ | |
int a = va_arg(args, int); | |
if (a > max) max = a; | |
} | |
return max; | |
} | |
int minOf(int num, ...) | |
{ | |
va_list args; | |
int min; | |
register int i; | |
va_start(args, num); | |
for (i = 0; i < num; i++) | |
{ | |
int a = va_arg(args, int); | |
if (a < min) min = a; | |
} | |
return min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment