#include <iostream>
using namespace std;
void main()
{
char str1[50];
int i, l = 0;
cout<<"Find the length of a string:\n ";
cout<<"Input a string : ";
cin>>str1;
for (i = 0; str1[i] != '\0'; i++)
{
l++;
}
cout<<"The string contains "<<l<<" number of characters. "<<endl;
cout<<"So, the length of the string "<<str1<<" is :"<< l;
cout<<endl;
system ("pause");
}
Test Data :
Input a string : welcome
Expected Output :
The string contains 7 number of characters.
So, the length of the string welcome is : 7
using namespace std;
void main()
{
char str1[50];
int i, l = 0;
cout<<"Find the length of a string:\n ";
cout<<"Input a string : ";
cin>>str1;
for (i = 0; str1[i] != '\0'; i++)
{
l++;
}
cout<<"The string contains "<<l<<" number of characters. "<<endl;
cout<<"So, the length of the string "<<str1<<" is :"<< l;
cout<<endl;
system ("pause");
}
Test Data :
Input a string : welcome
Expected Output :
The string contains 7 number of characters.
So, the length of the string welcome is : 7
Write a C++ program to find the length of a string without using the library function. .
Reviewed by Unknown
on
June 20, 2017
Rating:
No comments: