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
- Which command shows the last 20 lines and continues following appended lines?
- A Java method isLeaf(TreeNode node) is intended to check if a given node is a leaf in a binary tree. class TreeNode { int val; TreeNode left, ...
- To discard all pending data changes :
- Which of the following is NOT a characteristic of method overloading?
- Which of the following is a NoSQL database commonly used in Big Data?
- Which is connectionless and unreliable protocol
- In the classic bounded-buffer producer-consumer problem using a buffer of size N, to what value should the counting semaphore 'empty' (tracking free buffer...
- What is 'virtual memory' in the context of operating systems?
- What is the primary function of cache memory in a computer system?
- What is the purpose of the fork() system call in Unix-based operating systems?
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)