Added code to calculate output and print
removed unneccesary code in change c++. added complete loop.
added conditioning to calculate loop