From ffaf9b42c1e2cbe5b2f47a07ac96224602844a86 Mon Sep 17 00:00:00 2001 From: SHITHIN SHETTY <92690951+shithinshetty@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:50:22 +0530 Subject: [PATCH] Create Happy Number --- algorithms/CPlusPlus/Maths/Happy Number | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 algorithms/CPlusPlus/Maths/Happy Number diff --git a/algorithms/CPlusPlus/Maths/Happy Number b/algorithms/CPlusPlus/Maths/Happy Number new file mode 100644 index 00000000..09d578c5 --- /dev/null +++ b/algorithms/CPlusPlus/Maths/Happy Number @@ -0,0 +1,21 @@ +class Solution{ +public: + int isHappy(int N){ + + int sum=0,r; + while(N!=0) + { + r=N%10; + sum=sum+(r*r); + N=N/10; + } + + if(sum==1) + return 1; + else if(sum<10) + return 0; + else + return isHappy(sum); + + } +};