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:
#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:
Armstrong Program in C++
ReplyDeleteArmstrong 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.
happy valentines images
ReplyDeletepromise images
kiss day in india
promise day wallpaper
kiss day msg
Happy Valentines Day 2017
ReplyDeleteValentine's Day History
Valentine's Day Images
Valentine's Day Wishes For Boyfriend
Valentine's Day Love Quotes
Valentine's Day Cute Images Download
Happy Valentine's Day FB Status
Happy Valentine's Day HD Wallpapers 3D
Happy Valentines Greeting Cards
Romantic Wishes For Girlfriend
Happy Valentine's Day Romantic Wishes
ReplyDeleteValentine's Day Cards Download
Happy Valentine's Day 3D Wallpapers
Valentine's Day Images For Facebook
Valentine's Day Facebook Status
Valentine's day images for Girlfriend
Romantic Valentine's Day SMS
Valentine's Day 2017 Quotes
Valentine's Day Story
Valentine's Day Romantic Wishes For Husband
Holi festival images 2017 Holi wishes 2017 Happy holi images 2017 Haapy holi 2017 wishes
ReplyDeleteThank 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