/*
Program to count the no. of words in a string....
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50];
int i,j,c=1;
cout<<"Enter the string:";
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
c++;
}
if((a[i]=='\0') && (a[i-1]==' '))
c--;
cout<<"The no. of words are:"<<c;
getch();
}
Program to count the no. of words in a string....
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50];
int i,j,c=1;
cout<<"Enter the string:";
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
c++;
}
if((a[i]=='\0') && (a[i-1]==' '))
c--;
cout<<"The no. of words are:"<<c;
getch();
}
0 comments:
Post a Comment