The kids need to clear a simple test to secure admission in the nursery class. They need to spell their name and they also need to tell the number of letters in their name. Some of the kids had very long names and the interview panel members found it time-consuming to count the number of letters in the name. One of the panel members has just started to learn to programme and she decided to write a C program to count the number of characters in the name. She knew that it was an easy task as the good old strlen function is available in C. Can you help her out in this task?
Write a C program to find the number of characters in the string.
Input Format:
Input consists of a single string. Assume that the maximum length of the string is 50 and it contains only alphabets.

Enter the name
Punitha
The number of letters in the name is 7

Program Code:
#include<stdio.h>
int main()
{
    char str[100];
    int i=0; int l=0;
    printf("Enter the name");
    scanf("%s",str);
    while(str[i]!='\0')
    {
        l++;
        i++;
    }
    printf("\nThe number of letters in the name is %d",l);
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:

  1. This is only for lenght.But question is different

    ReplyDelete