Find the Length of a String

Write a Program to Find the Length of a String.

C Program


#include <stdio.h>
int main()
{
    char str[] = "Hello World";
    int len = 0;
    int i = 0;
    while (str[i] != '\0')
    {
        len++;
        i++;
    }
    printf("Length of string is %d"len);
    return 0;
}

Input:

str[]="Hello World"

Output:

Length of string is 11


No comments:

Post a Comment