aded midoint implementation in C