Question

Write a recursive function in C language to calculate the sum of all digits in a long integer provided as input.

24 Apr 2024
Answer :
Word Count : 368

To write a recursive function in C language that calculates the sum of all digits in a long integer, we can follow these steps:

1. Define the recursive function prototype.
2. Define the base case.
3. Define the recursive case.

Here's the code for the recursive function:

```c
#include <stdio.h>

// Recursive function to calculate the sum of digits
int sumOfDigits(long num);

int main() {
    long num;
   

__________ ___ __________ ______ ____.
_______ ___ ______ ______ _______ ________ ________ ________ __________ __________ _______ __________.
___ __________ ________ ____ ________ ______ ___.
_________ ____ __________ _______ _______ ______ ____ __________ ______ ____.
________ __________ __________ _________ __________ ______ _______.
____ __________ ______ _______ _____ _______ ______ _______ _____ ______ ________.
_______ ________ __________ ____ ___ ________ ____ ________ _______.
___ _________ _____ ______ _______ ____ ______ _________ ____ _____ _________ ______.
_____ _________ ____ _____ __________ _________.
__________ _____ ___ _____ ______ _________ ___ ___ _________ ___.
________ _____ ___ ___ _______ ______ ________ ____ ___ ________.
_______ ____ _______ _______ __________ ____ __________ _______ _______.
______ __________ ___ _________ __________ _____ ___.
__________ _______ ________ _____ __________ ______ ______ __________ ____ _____.
________ __________ _____ ___ _____ ____ __________ __________ _______.
__________ _______ _____ _______ ___ _______ ________ __________ _____.
__________ _______ ________ ______ __________ ____ __________ _____.
_____ ______ ______ ____ _____ ______ ________ ________.
_____ __________ __________ ______ __________.
____ _____ ___ __________ _______ ________ __________ ___ ______.
_______ __________ ___ ________ __________ ________.
_________ ________ ____ __________ ________ __________ _____ ______ ____ ______ _______.
____ ___ _______ _______ ________ ___.
_________ ________ _______ ________ __________ ___ ____.
____ __________ ______ ________ ____ ________ ___ ___.
______ ___ ______ ______ ___ _______.
______ _________ ___ ___ ___.
______ _____ _________ _________ ______ _______ _____ ________ ____.
_______ ____ ________ _________ __________ ________ ________ ______.
____ ____ ___ __________ ________ ___ _________ _________ _________.
______ _________ ________ _________ _____ __________ ______ ________ _________ _____ _______.
_____ ____ ________ _______ ________ ________ _________ ________.
__________ ___ ___ _____ _____ _____ ____ ___ _______ ____ _______.
__________ ____ _____ ____ ___ _____ _______ ______ ___.
__________ __________ _________ _________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 31 2023 - Write a recursive function in C language to calculate the sum of all d | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→