adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to find the length of the string using recursive function

Program in C and C++ to find the length of the string using recursive function
C Program
#include<stdio.h>
 int len(char *str){
 	static int i = -1;
 	i += 1;
    if(str[i] == '\0')
      return 0;
    else
      len(str);
      return i;	
 }
 
int main(){
    char str[] = "om prakash";
    printf("Length : %d",len(str));	
    return 0;
}
C++ Program
#include<iostream>
 using namespace std;
 int len(char *str){
 	static int i = -1;
 	i += 1;
    if(str[i] == '\0')
      return 0;
    else
      len(str);
      return i;	
 }
 
int main(){
    char str[] = "programming.om";
    cout<<"Length : "<<len(str);	
    return 0;
}

Output :-







Related Programs 1.

Post a Comment

0 Comments