You might have to modify the input file so that your input set of angles reflects the fact that 359.99 is almost the same as 0. Maybe using unsigned type if you need an absolute value for the mean and subtract from every angle 360 degrees
Post some relevant code to get a better idea about design of your program.