Advertisement
Guest User

Median i c++

a guest
Sep 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. //Finds the median
  2. float median;
  3. if(aVector.size() % 2 == 0){
  4. float val1 = aVector[aVector.size() / 2 - 0.5] ;
  5. float val2 = aVector[aVector.size() / 2 + 0.5] ;
  6. median = (val1 + val2) / 2 ;
  7. }else{
  8. median = aVector[(aVector.size() - 1) / 2] ;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement