The sum of the first four term of a G.P.is 30 and last term four term is 960. If the first term is 2 and last term is 512 respectively.calculate common ratio

It appears that you have

a = 2
512/2 = 2^8, so r=2
The sums really are not needed, but to verify,
2+4+8+16 = 30
64+128+256+512 = 960