code is working for positive numbers but not working for negative numbers where is the problem