Skip to content

Commit

Permalink
Added happy number program.
Browse files Browse the repository at this point in the history
  • Loading branch information
shivhek25 committed Jun 4, 2017
1 parent 79d9c61 commit 74b6428
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Happy_number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* A happy number is a number whose sum of digits is calculated until the sum is a single digit,
and this sum turns out to be 1 */
#include <iostream>
using namespace std;
int main()
{
int n,k,s=0,d;
cout << "Enter a number:";
cin >> n;
s=n;k=n;
while(k>9)
{
while(k!=0)
{
d=n%10;
s+=d;
n/=10;
}
k=s;
s=0;
}
if(k==1)
cout << n << " is a happy number" << endl;
else
cout << n << " is not a happy number" << endl;
}

0 comments on commit 74b6428

Please sign in to comment.