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;
    printf("Enter a long integer: ");
    scanf("%ld", &num);
    
  ________ _______ _________ ____ _________ ______ _______ ________ ______ _________ _________.
______ ____ __________ _______ __________ ______ ______ _______ _____.
_________ ____ ___ ________ __________ ________ ______ ___.
_______ __________ ______ __________ __________ _______ _________ _____ ____ _________.
___ _____ ____ ______ ____.
____ ________ ________ _______ __________ __________ _____.
___ _______ _______ __________ _________.
____ ______ ___ ____ __________ ___ ____ _______.
__________ ________ ____ ________ _____ ____ _________ __________ __________ _________.
____ ________ _______ __________ ___ _____ _____.
________ _____ _______ __________ _____ _____ _____.
_______ __________ _________ _______ ___ _________ _____ ________ _______ ____ _______ ________.
______ ______ __________ __________ ______ _____.
_______ _____ _______ ___ ________ _____ ___ _____.
______ ________ _____ ___ ___ _________ ____ ___ __________.
_______ ___ ____ _______ ________ ________.
______ _________ _______ _________ _______ ____ ________ ______.
_______ _________ ______ ____ _______.
___ _____ ________ ________ ______ ______ _______ _________.
________ ______ ___ _____ ________ ________ _____ ______.
______ __________ ________ __________ __________ ___ __________ _____ _______ ________ ________ ___.
___ ______ _______ ________ ____.
___ _____ _________ ___ ___ _____.
____ ________ ____ __________ __________ _____ ___ __________ ____.
__________ _______ _____ ________ ______ _______ _____ ___ ___ ___ ________.
____ ________ ____ ____ ________ _____ ______.
________ ___ ____ _______ _______ _____ ________ ________ _________ _____ _____.
__________ _________ ________ ___ _____ ______ ________ ___ ___.
___ _______ _______ _________ _______ __________ _________ _______ _______.
______ _______ ______ ____ ___ ______ ________ __________.
______ ___ ____ ___ ____ ______ ______ ____ ____ ____ ___ ____.
_______ ____ _____ __________ ________ _________ __________ ______ ______ __________.
_____ _____ ____ _______ _____ _______ _____ ___.
______ _______.
Get Full Answer on WhatsApp

IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance Write a recursive function in C language to calculate the sum of all d
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→