Sunday 12 November 2017

C Program Find the Length of the Linked List using Recursion


Code:

#include   stdio.h

int length(char [], int);
int main()
{
    char word[20];
    int count;

    printf("Enter a word to count it's length: ");
    scanf("%s", word);
    count = length(word, 0);
    printf("The number of characters in %s are %d.\n", word, count);
    return 0;
}

int length(char word[], int index)
{
    if (word[index] == '\0')
    {
        return 0;
    }
    return (1 + length(word, index + 1));
}

Output:

Enter a word to count it's length: 5
The number of characters in 5 are 1.

Enter a word to count it's length: Executecodes
The number of characters in executecodes are 12.


More C Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...