Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Exercise1
- {
- public static int DigitSum(int n1)
- {
- if(n1 == 0) {
- return 0;
- } else {
- return ((n1 % 10) + DigitSum(n1 / 10));//calling the function DigitSum itself
- }
- }
- public static int test(int n1)
- {
- int sum;
- sum = DigitSum(n1);//call the function for calculation
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement