The first and last terms of an A.P. are a and l respectively. If s is the sum of all the terms of the A.P., then the common difference of the A.P. is
l2−a2s−(l+a)
l2−a22s−(l+a)
l2+a22s−(l+a)
l2+a2s−(l−a)
Let n be the number of terms. Then
s=n2(a+l)⇒n=2sa+l
Also,
d=l−an−1=(l−a)(l+a)2s−(l+a)=l2−a22s−(l+a)