This solution didn’t accurately done by me but i tried to understand how to solve it from various sources …..
http://math.stackexchange.com/questions/531432/solving-a-recurrence-relation-using-repeated-substitution
http://www.brpreiss.com/books/opus4/html/page41.html
http://www.questtosolve.com/browse.php?pid=10014
http://www.cprogramdevelop.com/2125057/
#include <stdio.h> int main() { int cases,i,j,n; double a0,aN,cI,sum=0; scanf("%d",&cases); for(i=1;i<=cases;i++){ if(i>1) printf("\n"); scanf("%d",&n); scanf("%lf",&a0); scanf("%lf",&aN); for(j=0;j<n;j++){ scanf("%lf",&cI); sum+=(n-j)*cI; } printf("%.2lf\n",(n*a0+aN-2*sum)/(n+1)); } return 0; }