Contact Learn C
Copy Program Share Program

Program 268: Program to print all Happy Numbers till N

Program 268: Program to print all Happy Numbers till N

#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);
  }
   }
  
}
Learn Program to print whether given Number is Happy or not 
Explanation:

//Coming Soon

Output:
Program to print all Happy Numbers till N




Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide