HackerRank Calculate the Nth term Solution in C