Dear student
Let the number of pencils he sold be x
so the amount of money shopkeeper loss by selling x pencils =40x paise
The amount of money shopkeeper earns by selling 45 pens =45*1=Rs45=4500 paise
net loss is given as Rs 5=500 paise
so,
40x-4500=500
40x=5000
x=5000/40
x=125 pencils
REGARDS