c program to calculate length the string using recursion and function
In this program, we will read a string through user and calculate the length of the string using recursion in c programming language. We will not use standard function strlen() to calculate the length of the string.
required knowledge :
string , for loop , function and recrusion
Example :
Input : atikurrahman
Output : length = 13
calculate length the string using function and recursion program code :
#include<stdio.h>
int len(char *str)
{
static int count=0;
if(*str!=0)
{
count++;
len(++str);
}
else
return count;
}
int main()
{
char strin[100];
printf("Enter the string name: ");
scanf("%s",&strin);
int bb=len(strin);
printf("length = %d",bb);
return 0;
}
OUTPUT :

No comments