SHARE
TWEET

Untitled

a guest Sep 15th, 2019 81 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 digit,n=0;
  6.     int sum=0;
  7.  
  8.     for(int x=1;x<10;x++) {
  9.         int currentNumber=x;
  10.        
  11.         do {    
  12.             sum = 0;
  13.    
  14.             while (currentNumber != 0) {
  15.                 digit = currentNumber%10;
  16.                 sum = sum + digit*digit;
  17.                 currentNumber=currentNumber/10;
  18.             }
  19.             currentNumber = sum;
  20.         } while(sum != 42 && sum != 1);
  21.        
  22.         while(currentNumber != 42 && currentNumber != 1) {
  23.             sum = 0;
  24.             while (currentNumber != 0) {
  25.                 digit = currentNumber%10;
  26.                 sum = sum + digit*digit;
  27.                 currentNumber=currentNumber/10;
  28.             }
  29.             currentNumber = sum;
  30.         }
  31.        
  32.         if (sum == 42) {
  33.             n++;
  34.         }
  35.     }
  36.        
  37.         printf("%d\n",n);
  38.         return 0;
  39. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top