Find the length of the string using the inbuilt function

Problem statement:- Program to Find the length of the string using the inbuilt function.

Data requirement:-

   Input Data:- str

  Output Data:-len

Program in C

Here is the source code of the C Program to Find the length of the string using the inbuilt function.

Code:

#include<stdio.h>
#include<string.h>
int main()
{
    char str[30];
    printf("Enter the String:");
    scanf("%[^\n]",str);
    int len=strlen(str);
    printf("Your Enter String length is:%d",len);
}

Input/Output:
Enter the String:csinfo 360
Your Enter String length is:10

Program in C++

Here is the source code of the C++ Program to Find the length of the string using the inbuilt function.

Code:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    cout<<"Enter the String:";
    getline(cin,str);
    int len=str.length();
    cout<<"Your Enter String length is: "<<len;
}

Input/Output:
Enter the String:csinfo 360 com
Your Enter String length is: 14

Program in Java

Here is the source code of the Java Program to Find the length of the string using the inbuilt function.

Code:

import java.util.Scanner;
public class p2 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str;
System.out.println("Enter your String:");
str=cs.nextLine();
int len=str.length();
System.out.println("Your Enter String is: "+len);
cs.close();
}
}

Input/Output:
Enter your String:
Coronavirus 2020
Your Enter String is: 16

Program in Python

Here is the source code of the Python Program to Find the length of the string using the inbuilt function.

Code:

str=input("Enter the String:")
print("Your Enter String is:", len(str))

Input/Output:
Enter the String:COVID-19 COVID-19
Your Enter String is: 17

Post a Comment

0 Comments