Code used in these answers.
Factorials Program(Q1)
Pyramid numbers Program(Q2)
Iterative method program(Q2)