Why are you storing the temperatures in an array, during the averaging process? The array is completely unnecessary.
if ( tempc < 40 && tempc > 10 ) {
This is hard to read.
if(tempc > 10 && tempc < 40)
{
is much closer to how people decide to do things. The compiler doesn't care, but it's easier to maintain understandable code.
What, exactly, is connected to pin 3? What kind of fan are you using?