used arrays instead of scalars for computations, and displayed results in a loop