Advertisement
codegod313

Ele4ka(recursus)

Nov 13th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int F(int n) {
  6. if (n % 10 > 0) {
  7. return(n % 10);
  8. }
  9. if (n == 0) {
  10. return 0;
  11. }
  12. return F(n / 10);
  13. }
  14.  
  15.  
  16. int main()
  17. {
  18. int p, q;
  19. int s = 0;
  20. cout << "Enter p and q" << endl;
  21. cin >> p >> q;
  22. while (p >=0 && q >=0)
  23. {
  24. for (int i = p; i <= q; i++) {
  25. s += F(i);
  26. }
  27.  
  28. cout << "There is the sum " << s << endl;
  29. cin >> p >> q;
  30. s = 0;
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement