Advertisement
danzylrabago

RecursionDigitSum

Mar 26th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. using System;
  2. class Exercise1
  3. {
  4.  
  5. public static int DigitSum(int n1)
  6. {
  7. if(n1 == 0) {
  8. return 0;
  9. } else {
  10. return ((n1 % 10) + DigitSum(n1 / 10));//calling the function DigitSum itself
  11. }
  12.  
  13. }
  14.  
  15. public static int test(int n1)
  16. {
  17. int sum;
  18.  
  19. sum = DigitSum(n1);//call the function for calculation
  20.  
  21. return sum;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement