Question
Consider the following C code snippet designed to calculate the sum of digits of a non-negative integer: #include int sumDigits(int
Consider the following C code snippet designed to calculate the sum of digits of a non-negative integer: #include int sumDigits(int
n) { if (n == 0) { return 0; } // Error in recursive step return sumDigits(n / 10); } int main() { printf("%d\n", sumDigits(123)); return 0; } What is the error in the sumDigits function above, and how should it be corrected to correctly calculate the sum of digits of a non-negative integer?
More IT Operating System Questions
- In a code flow involving frequent insertions and deletions, which type of Binary Search Tree is preferred to guarantee O(log n) time complexity for these o...
- Which isolation level prevents dirty reads and non-repeatable reads, but still permits phantom reads?
- The following Java code attempts to demonstrate method overloading, but it has a compilation error. How should it be corrected? public class Calculator ...
- What does the term 'elasticity' refer to in the context of cloud computing?
- A system design decision requires that a process must request and be allocated all the resources it will ever need at once, before it begins execution, and...
- What is the typical time complexity for removing the highest-priority element (using poll()) from a java.util.PriorityQueue with N elements? import ...
- Inheritance is an OOP principle that establishes an "is-a" relationship between classes. What does this relationship primarily allow?
- A Java method tries to get the length of an array and a string. public class LengthChecker { public void checkLengths() { String[] names = {...
- Which of the following is a key characteristic of OLAP systems?
- A priority queue is a special type of queue where each element has a priority. What is the typical time complexity for inserting an element into a priority...
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)