geeksforgeeks
  • Courses
  • Tutorials
  • Practice
  • Jobs
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
Videos
June 07, 2022 |10.3K Views

Happy Numbers

CPP, Maths, Magic Numbers, Happy-numbers, CPP Programs
 Save  Share  1 Like
Description
Discussion

A number is called happy if it leads to 1 after a sequence of steps wherein each step number is replaced by the sum of squares of its digit that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.

Examples :

Input: n = 19
Output: True
19 is Happy Number,
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
As we reached to 1, 19 is a Happy Number.

Input: n = 20
Output: False

Happy Numbers: https://www.geeksforgeeks.org/happy-number/

Recommendations
Video Thumbnail
10:14
Video Thumbnail
86.4K Views | 11/01/2025...
Program to Find the Sum of All Digits of a Number
Video Thumbnail
10:37
Video Thumbnail
30.6K Views | 09/01/2025...
Graham Scan Algorithm
Video Thumbnail
03:53
Video Thumbnail
25.7K Views | 08/01/2025...
Primality Test (Introduction and School Method)
Video Thumbnail
04:41
Video Thumbnail
11.5K Views | 08/01/2025...
C++ Program to Find Roots of a Quadratic Equation
Video Thumbnail
08:23
Video Thumbnail
8.6K Views | 03/01/2025...
C++ Program on Multiplication of Two Matrices
Video Thumbnail
08:00
Video Thumbnail
3.9K Views | 03/01/2025...
JavaScript Program to Check if Two Strings are Anagrams
Video Thumbnail
03:36
Video Thumbnail
3.2K Views | 16/08/2024...
C++ Program to Return Maximum occurring Character in an Input String
Video Thumbnail
11:51
Video Thumbnail
920 Views | 18/07/2024...
Palindrome Number
Video Thumbnail
03:12
Video Thumbnail
110.0K Views | 18/07/2024...
C++ Program to Find GCD
Video Thumbnail
10:49
Video Thumbnail
43.7K Views | 17/07/2024...
C++ Program to Calculate Power of a Number
GeeksforGeeks
location
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
location
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play StoreGFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Careers
  • Contact Us
  • Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Practice Problems
  • Connect
  • Blogs
  • Upskill Courses
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • GATE
  • School Subjects
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Data Science
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • MongoDB Certifications
  • Offline Centers
  • Noida
  • Bengaluru
  • Hyderabad
  • Kolkata
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved