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 programming 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. Seeing her interest towards programming, another senior panel member who is also running a software concern decided to test her programming skills. He asked her to write the program without using the strlen function. Can you please help her out?
Write a C program to find the number of characters in the string.
Input Format:
Enter the name
Punitha
Output Format:
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;
}
Post A Comment:
0 comments: