Facebook Google Plus YouTube

C program count length of string using recursion(without build in function).

Count length of string using recursion(without build in function).

 

#include<stdio.h>
#include <string.h>
int length_count(char *line)
{
  static int count = 0;
    if(*line != NULL)
    {
        count++;
    length_count(++line);
    }
    return count;
}
int main()
{
char str[] ="Learn and share blog";
int count=0;
printf("The  string length is :\t");
count=length_count(str);
printf("%d",count);
return 0;
}

Output:

The string length is : 20

Leave a Reply

%d bloggers like this: