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
- What is the primary purpose of "virtual memory" in an operating system?
- In pipelining, the CPU executes each instruction in a series of following stages: Instruction Fetching (IF) —–> Instruction Decoding (ID) —–> Instruction E...
- Which of the attributes shown below is a simple attribute?
- What is the key functional difference between RAM (Random Access Memory) and ROM (Read-Only Memory) in a computer system?
- The Banker's Algorithm for deadlock avoidance requires which piece of information to be declared by each process in advance, before it begins execution?
- CDATA is used in XML to:
- What is the average-case time complexity for search, insertion, and deletion operations in a well-designed hash table?
- When analyzing the performance of a sorting algorithm, what is a common operation to count for time complexity?
- What is the primary purpose of Encapsulation in Object-Oriented Programming?
- In contiguous memory allocation, which statement correctly compares the Best-Fit and Worst-Fit memory allocation strategies in terms of fragmentation behav...
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)