Examples of C part 51 print all happy number till n

Program :
#include<stdio.h>
#include<math.h>
main()
{
 int i,j,num,happy,temp,sum=0;
 printf("Enter number till what you want happy numbers to be displayed\n");
 scanf("%d",&happy);
   for(i=1;i<=happy;i++)
   {
    sum=0;
    num=i;
    temp=num;
     while(sum!=1 && sum!=4)
  {
   sum=0;
   while(num>0)
  {
    j=num%10;
    sum+=(j*j);
    num=num/10;
  }
  num=sum;
  }
  if(sum==1)
  {
   printf("%d\n",i);
  }
   }

}
Output:
Enter number till what you want happy numbers to be displayed
30
1
7
10
13
19
23
28
Explanation:
//Coming Soon