Function allDigitSum – CTS PATTERN

You are required to complete the given code by implementing the logic for the function. You can click on Run anytime to check the compilation/ execution status of the program. You can use printf to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write the main() function as it is not required.

Code Approach: For this question, you will need to implement the logic for the function.

The function allDigitSum(int *arr, int LENGTH) accepts an array arr and an integer LENGTH as the size of arr. It is supposed to return the sum of digits of all the integers in the array.

You will have to complete the code to make it work and pass all test cases.

int allDigitSum(int *arr, int LENGTH)
{
    int s=0;
    for(int i=0;i<LENGTH;i++){
        while(arr[i]>0){
            int r=arr[i]%10;
            s+=r;
            arr[i]/=10;
        }
    }
    return s;
}
Previous Article

Function getPower - CTS PATTERN

Next Article

Function countElement - CTS PATTERN

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *