fork download
  1. #include <stdio.h>
  2.  
  3. int max5(int value1, int value2, int value3, int value4, int value5)
  4. {
  5. int theMax; /* the max value */
  6.  
  7. // could be done with a series of if, else if, and/or
  8. // else statements ... use of the && operator would be a good idea
  9.  
  10. if (value1 > value2 && value1 > value3 && value1 > value4 && value1 > value5) // determine largest value
  11. theMax = value1;
  12. else if (value2 > value3 && value2 > value4 && value2 > value5)
  13. theMax = value2;
  14. else if (value3 > value4 && value3 > value5)
  15. theMax = value3;
  16. else if (value4 > value5)
  17. theMax = value4;
  18. else
  19. theMax = value5;
  20.  
  21. return theMax; // return the max value
  22. }
  23.  
  24. int main() {
  25. printf("Largest value: %d\n", max5(5, 2, 8, 4, 1));
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Largest value: 8