C++ Program to Count Number of Words in String

Factorial of huge numbers contain such a large number of digits. For instance factorial of 100 has just about 158 digits.

So there is no information type accessible to store such a long worth. In any case, we can discover factorial for

huge numbers utilizing straightforward augmentation strategy that we utilized in our educational time.

Underneath I have shared the program for it.

Program

#include<iostream>
#include<stdio.h>
 
using namespace std;
 
int main()
{
	char a[100];
	int i,count=1;
	
	cout<<"Enter a string:";
	gets(a);
	
	for(i=0;a[i]!='\0';++i)
	{
		if(a[i]==' ')
			count++;
	}
	
	cout<<"\nThere are "<<count<<" words in the given string";
 
	return 0;
}

Output

Enter a string:how are you buddy?

There are 4 words in the given string

Leave a Comment

error: Alert: Content is protected!!