Program to print the length of a string

Program to print the length of a string

21 April 2023

21 April 2023

Write a Program to print the length of a string



If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023

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))


If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023


Related Articles

Ask Us Anything !