Happy Number TIme Limitation issue

the error means the program runs forever unless stopped.
the code above should have this behavior for n a not happy number, for example 4, where it will iterate endlessly in thewhile(sum!=1){ /// for n = 4 sum = 0; while(n>=10){ r = n%10; sum=sum + (r^2); n = n/10; } Sum+= n^2; // here sum == 16 and n =0 after the 1st iteration // after the second iteration sum = 0 and n = 0 and the while will never finish }