Where i am doing wrong ...please tell me using the same approach as used by me

in main while calling function you pass value of n as sum and value of sum as n