Программа перестает работать всякий раз, когда я ввожу число « unhappy » и ничего не печатаю
Вот результат:
Когда я введите счастливое число 
When I enter the unhappy number (then output screen even after 2 minutes of time)

#include <stdio.h>
//This is a program to check if a number is happy or not
int main()
{
int n, r, sum, tmp; // n = number, r = remainder
printf("Enter a number:");
scanf("%d", &n); // input number
tmp = n;
do {
sum = 0;
while (tmp > 0) {
r = tmp % 10;
sum += r*r;
tmp = tmp / 10;
}
tmp = sum;
} while (tmp > 1);
if (sum == 1) {
printf("%d is a happy number",n);
} else {
printf("%d is not a happy number",n);
}
return 0;
}