Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int n, sum, d;
- printf("Enter a number to check if it's happy: ");
- scanf("%d", &n);
- while (n > 0) {
- sum = 0;
- while (n > 0) {
- d = (n%10);
- n/=10;
- sum += d*d;
- }
- n = sum;
- if ( n < 10 )
- break;
- }
- if (n == 1)
- printf("Happy number!");
- else
- printf("Not a happy number.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement