#include <iostream>
#include<string>
using namespace std;
int main()
{
string s1;
int i,n,a=0;
s1="Hello World";
n=s1.length();
for(i=0; i<=n; i++)
{
if (s1[i]==' ')
a=a+1;
}
cout<<"No. of words in string are: "<<a+1;
return 0;
}
#include<string>
using namespace std;
int main()
{
string s1;
int i,n,a=0;
s1="Hello World";
n=s1.length();
for(i=0; i<=n; i++)
{
if (s1[i]==' ')
a=a+1;
}
cout<<"No. of words in string are: "<<a+1;
return 0;
}
No comments:
Post a Comment