SHARE
TWEET

Untitled

a guest Dec 8th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n, sum, d;
  6.  
  7.     printf("Enter a number to check if it's happy: ");
  8.     scanf("%d", &n);
  9.  
  10.     while (n > 0) {
  11.         sum = 0;
  12.         while (n > 0) {
  13.             d = (n%10);
  14.             n/=10;
  15.             sum += d*d;
  16.         }
  17.         n = sum;
  18.  
  19.         if ( n < 10 )
  20.             break;
  21.     }
  22.  
  23.     if (n == 1)
  24.         printf("Happy number!");
  25.     else
  26.         printf("Not a happy number.");
  27.  
  28.     return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top