Skip to main content

Featured

functions in Python

C++ program to check happy number

/*Following program checks whether a number is happy number or not. Happy Number Example: 19. If the number's digits squared and added till we get 1, the number is happy number*/
#include<iostream.h>
#include<math.h>
long func(long);
void main()
{
long a;
cout<<"\tEnter a number\n";
cin>>a;
long y=func(a);
if(y==1)
cout<<"Happy Number";
else
cout<<"Unhappy Number\n";

}

long func(long x)
{
 long sum=0,rem;
 while(x>0)
 {
 rem=x%10;
 sum=sum+pow(rem,2);
 x=x/10;
 }
if(sum>10)
func(sum);
else
return sum;
}

OUTPUT:

Comments

  1. Armstrong Program in C++

    Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits is equal to the number itself.
    For example 153 is armstrong number, 132 is not prime number. Armstrong program in c++ is very simple and easy to write.

    ReplyDelete
  2. Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards, Vistara customer care

    ReplyDelete

Post a Comment

Popular Posts