#include<iostream>
using namespace std;
int countword(char []);
int main()
{
char name[50];
cout<<"Enter a string:";
cin.getline(name,50);
cout<<"\n\nThe number of words in the string is "<<countword(name)+1<<"\n\n\n";
return 0;
}
int countword(char n[])
{
int count=0,i=0;
while(n[i]!='\0')
{
if(n[i]==' ')
count++;
++i;
}
return count;
}
using namespace std;
int countword(char []);
int main()
{
char name[50];
cout<<"Enter a string:";
cin.getline(name,50);
cout<<"\n\nThe number of words in the string is "<<countword(name)+1<<"\n\n\n";
return 0;
}
int countword(char n[])
{
int count=0,i=0;
while(n[i]!='\0')
{
if(n[i]==' ')
count++;
++i;
}
return count;
}
0 comments:
Post a Comment