Coding:
#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
char str[200];
int i=0,word=0,ch=0;
clrscr();
textcolor(YELLOW);
printf("\nEnter the String (Max=200 characters): ") ;
gets(str);
while(str[i]!='\0')
{
if(str[i]==' ')
{
word++;
ch++;
}
else
{
ch++;
}
i++;
}
printf("\nNumber of Characters = ");
cprintf("%d",ch);
printf("\nNumber of Words = ");
cprintf("%d",word+1);
getch();
}
Output:
No comments:
Post a Comment