Obtain the expression for energy stored in a capacitor C in terms of charge Q on

Energy transformed

Average of potencial diffrence

So we can say that energy stored in the capacitor is equal to of the narrowstrip on the diagram above.

Ideal capacitor in theory will have the same energy stored as charge. Just in practice to count energy stored in capacitor we have to multiply charge Q by half energy supplied. Just because of the resistance in the circuit, half of the energy will change to heat.