Description
Get a string as the input and find the length of the string.
Input
Hello
Output
5
C Program
#include<stdio.h>
#include<string.h>
int main()
{
char str[20];
printf("Enter a string: ");
scanf("%s",str);
printf("%ld",strlen(str));
}
C++ Program
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[20];
cout<<"Enter a string: ";
cin>>str;
cout<<strlen(str);
}
Java
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string: ");
String str1 = sc.nextLine();
System.out.println(str1.length());
}
}
Python
str1=input("Enter a string: ")
print(len(str1))