Users Online

· Guests Online: 34

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program Find the Length of the Linked List using Recursion

This C Program uses recursive function & calculates the length of a string. The user enters a string to find it’s length.

Here is the source code of the C program to find the length of a string. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C program to find the length of a string
*/
#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));
}

$ cc pgm17.c
$ a.out
Enter a word to count it's length: 5
The number of characters in 5 are 1.

$ a.out
Enter a word to count it's length: sanfoundry
The number of characters in sanfoundry are 10.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.74 seconds
10,276,774 unique visits