The below code runs perfectly.Gives the correct output but, the moment I change the sign of the variables from signed to unsigned the program runs into an infinite loop. The
As other answers already noted, the loop
for(i=count-1;i>=0;--i)
is an infinite loop if i is unsigned. It can be rewritten in a different form as
for (i = count - 1; i != -1; --i)
which will work as intended for both signed and unsigned i. However, some might find it less readable than the original.