Is the switch connected to Input1? Or is there a separate "reset trigger" input?
Assuming your fan sensor switch is connected to an input named: fanSwitch:
Within the custom function FanSWCnt you can put your statement:
C = C+1
which will increment the counter.
If you have a separate reset switch to reset the counter then you can connect the reset switch to another custom function and then within that CF you run the statement:
C = 0
to reset it.