Answer to Question #268822 in C for Phn

Question #268822

Vijayalaksmi wants to check the number of times the word “ India” appears in a given


paragraph. Write a C program without using string function to do

1
Expert's answer
2021-11-19T17:09:48-0500
#include <stdio.h>
#include <string.h>
int main()
{
	int ctr=0,i,frequency=1;
        int I,n,d,m,a,spc;
	char str[100];
	
	
       printf("\n\nFind the number of times the word 'india ' in any combination appears :\n");


	printf("Input the string : ");
	fgets(str,sizeof str,stdin);


        ctr=strlen(str);


	for(i=0;i<=ctr-5;i++)
	{
		m=(str[i]=='i'||str[i]=='I');
		n=(str[i+1]=='n'||str[i+1]=='N');
		d=(str[i+2]=='d'||str[i+2]=='D');
		I=(str[i+3]=='i'||str[i+3]=='I');
		a=(str[i+4]=='a'||str[i+4]=='a');
		spc=(str[i+5]==' '||str[i+5]=='\0');
		if ((m&&n&&d&&I&&a&&spc)==1)
		   frequency++;
	}
	printf("The frequency of the word \'india\' is : %d\n\n",frequency);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS