convert c to phyton 1

convert c to phyton

#include 
#include 

int mylen(char *n);

int mylen(char *n)
{
  int count=0;
  for(int i=0; n[i]!='\0'; i++){
    count++;
  }
  printf("count=%d",count);
  return count;
}

int main(void){
  char name[20];
  
  printf("enter name:\n");
  scanf("%s",&name);
  puts(name);
  int len = mylen(name);
  printf("length = %d",len);
  return 0;
}

Here is what the above code is Doing:
1. We are taking a string input from the user.
2. We are passing the string to a function mylen() which returns the length of the string.
3. We are printing the length of the string.

Similar Posts