This is a C program to find the frequency of the word ‘the’ in a given sentence.
This program takes the sentence as input and finds the frequency of the word ‘the’ in a given sentence.
1. Take any sentence as input.
2. Check for the word ‘the’ in the input sentence.
3. Use a variable to keep the count of number of ‘the’ in the sentence.
Here is source code of the C program to find the frequency of the word ‘the’ in a given sentence. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to accept a string and find the number of times the word
* 'the' appears in that string
int count = 0, i, times = 0, t, h, e, space;
puts("Enter a string:");
/* Traverse the string to count the number of characters */
while (string[count] != '\0')
/* Finding the frequency of the word 'the' */
for (i = 0; i <= count - 3; i++)
t =(string[i] == 't' || string[i] == 'T');
h =(string[i + 1] == 'h' || string[i + 1] == 'H');
e =(string[i + 2] == 'e'|| string[i + 2] == 'E');
space =(string[i + 3] == ' ' || string[i + 3] == '\0');
if ((t && h && e && space) == 1)
printf("Frequency of the word 'the' is %d\n", times);
1. Take any sentence as input and store it in the array string.
2. If the input string has ‘t’, ‘h’, ‘e’ and ‘ ‘ consecutively, then store that values in the variables t, h, e and space respectively.
3. Use the variable times to count the number of ‘the ‘ in the input sentence. Increment the variable times if and only if the variables t, h, e and space have values in it.
4. Print the variable times as output and exit.
Enter a string: The gandhi jayanthi is celeberated on october 2 is the day that he has born. Frequency of the word 'the' is 2
Sanfoundry Global Education & Learning Series – 1000 C Programs.