Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. int inputarray[50] = {1,2,3,4,5}; // etc etc etc
  2.  
  3. int outOdds[50] = {-1}; // init them all to -1
  4. int outEvents[50] = {-1};
  5.  
  6.  
  7. void findLimits( int* array, int arrayLength, int &outLowest, int &outAvg, int &outHighest )
  8. {
  9. outLowest = outAvg = outHighest = array[0];
  10.  
  11. for (int i=0; i<arrayLength; i++)
  12. {
  13. outAvg += array[i];
  14. if (array[i] < outLowest) outLowest = array[i];
  15. if (array[i] > outHighest) outHighest = array[i];
  16. }
  17.  
  18. outAvg /= arrayLength;
  19. }
  20.  
  21.  
  22. void main()
  23. {
  24. int oddsIter = 0;
  25. int evensIter = 0;
  26.  
  27. for (int i=0; i<50; i++)
  28. {
  29. if (inputarray[i] % 1 == 0)
  30. {
  31. outOdds[oddsIter] = inputarray[i];
  32. oddsIter++;
  33. }
  34. else
  35. {
  36. outEvens[evensIter] = inputarray[i];
  37. evensIter++;
  38. }
  39. }
  40.  
  41. int evenLow, evenAvg, evenHigh;
  42. int oddLow, oddAvg, oddHigh;
  43.  
  44. findLimits(outOdds, oddsIter, oddLow, oddAvg, oddHigh);
  45. findLimits(outEven, evenIter, evenLow, evenAvg, evenHigh);
  46. }
Add Comment
Please, Sign In to add comment