Add files via upload

This commit is contained in:
Christian Bender
2017-12-23 18:30:49 +01:00
committed by GitHub
parent 220c0fbaf8
commit 4b7d334c6e
31 changed files with 2290 additions and 0 deletions

26
Others/Happy_number.cpp Normal file
View File

@@ -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=0;k=n;
while(k>9)
{
while(k!=0)
{
d=k%10;
s+=d;
k/=10;
}
k=s;
s=0;
}
if(k==1)
cout << n << " is a happy number" << endl;
else
cout << n << " is not a happy number" << endl;
}