Advertisement
ULK

Д. М. Златопольский (10.20.)

ULK
May 8th, 2023
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int SumOfThree(int m) {
  5.  
  6.     int sum = ((m / 100) % 10) + ((m / 10) % 10) + (m % 10);
  7.  
  8.     return sum;
  9. }
  10.  
  11. int main()
  12. {
  13.  
  14.     int k = 0;
  15.     for (int i = 100000; i < 999999; i++) {
  16.         if (SumOfThree(i/1000) == SumOfThree(i%1000)) {
  17.             k++;
  18.             cout << i << " <---- happy number " << endl;
  19.         }
  20.     }
  21.     cout << k << " - amount of 6-digit happy numbers ";
  22.    
  23.    
  24.     /* без функции
  25.  
  26.     int a, b, c, d, e, f;
  27.     int k = 0;
  28.     for (int i = 100000; i < 999999; i++)
  29.     {
  30.         a = i / 100000;
  31.         b = (i / 10000) % 10;
  32.         c = (i / 1000) % 10;
  33.         d = (i / 100) % 10;
  34.         e = (i / 10) % 10;
  35.         f = i % 10;
  36.  
  37.         if(a + b + c == d + e + f){
  38.             k++;
  39.             cout << i << " <---- happy number " << endl;
  40.         }
  41.     }
  42.     cout << k << " - amount of happy numbers ";*/
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement