It is essential to assume that there are no frictional forces acting on the projectile to be able to show that the range is maximum if it is initially launched with a velocity making an angle of 45 degrees with the horizontal.
The velocity of a projectile fired at a velocity V making an angle X with the horizontal can be divided into two components. The horizontal component is constant as in the absence of friction no force acts to change this. The vertical component V*sin X changes due to the gravitational force of attraction and at any time t is equal to V*sin X - g*t. If the vertical component is equal to 0 after a time T, 0 = V*sin X - g*T
=> T = V*sin X/g
The time that the projectile travels for is twice the time it takes to reach its maximum height at which point the vertical velocity is 0.
This gives the time that the projectile travels for equal to 2*V*sin X/g. In this time, the horizontal distance traveled is V*cos X*2*V*sin X/g.
=> D = V^2*sin 2X/g
The value of D is maximum for a changing angle of projection X when dD/dX = 0
dD/dX = (V^2/g)*2*cos 2X = 0
=> cos 2X = 0
=> 2X = 90
=> X = 45 degree
This shows that the distance traveled by a projectile is maximum when it is fired at a certain velocity if the angle of projection is 45 degrees.