Saturday, July 2, 2022

Sum of digits (Recursion)

 Sum of digits (Recursion)

Problem Statement
Given a number N, find the sum of all the digits of the number

Note: Use a recursive method to solve this problem.

static long  Sum(long  n) 
    {   long sum = 0;
 
        while (!= 0) {
            sum = sum + n % 10;
            n = n / 10;
        }
 
        return sum;
        }

No comments:

Post a Comment

ads vert

Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody

  Basic HTML Tables - Layout, HTML Tables, Attributes, Aside, Footer, Tr tag, Td tag, Th tag, Tbody < table >      < thead >    ...