Advertisement
Guest User

C++ Harshad numbers ... pls optimize

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5. int querSum(int eingabe);
  6. int harshad(int eingabe);
  7.  
  8. int main()
  9. {
  10.     int eingabe =0;
  11.     int harsh;
  12.     cin >> eingabe;
  13.     harsh = harshad(eingabe);
  14.     cout << harsh << endl;
  15.  
  16.     return 0;
  17. }
  18. int querSum(int eingabe)
  19. {
  20.     int querSum = 0;
  21.     while(eingabe > 0)
  22.     {
  23.         querSum += eingabe % 10;
  24.         eingabe /= 10;
  25.     }
  26.      return querSum;
  27. }
  28. int harshad(int eingabe)
  29. {
  30.     //int searchedharshad = querSum(eingabe);
  31.     while (eingabe % querSum(eingabe) != 0)
  32.     {
  33.         harshad(++eingabe);
  34.     }
  35.     return eingabe;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement