From 3c1f2c1d8e47d8795e43f5b7f0a5bad24eafc94f Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Fri, 29 Sep 2017 15:26:47 +0200 Subject: [PATCH] Fix happy number algorithm. Don't code when drunk or test it. --- Happy_number.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Happy_number.cpp b/Happy_number.cpp index ca252bd6e..f3571ac34 100644 --- a/Happy_number.cpp +++ b/Happy_number.cpp @@ -7,14 +7,14 @@ int main() int n,k,s=0,d; cout << "Enter a number:"; cin >> n; - s=n;k=n; + s=0;k=n; while(k>9) { while(k!=0) { - d=n%10; + d=k%10; s+=d; - n/=10; + k/=10; } k=s; s=0;