OUTPUTS (after running):
Enter the first string: DR. RAJIV
Entered the second string: DR. RAJIV
Entered strings are equal.
OUTOUTS 2 (after running):
Enter the first string: DR. RAJIV
Entered the second string: CHOPRA
Entered strings are not equal.
Example
9: Write a C program to count the frequency of occurrence of a character in a
given string.
Solution 9:
The program is as follows:
#include
#include
void main( )
{
char str[100], ch;
int i, count = 0, length;
printf(“\nEnter the string:”);
gets(str);
printf(“\nEnter the character to be searched:”);
scanf(“%c”, &ch);
length = strlen(str);
(i=0; i< length; i++)
{
if (str[i] = = ch)
count++;
}
printf(“\n The frequency of the occurrence of %c is %d\n\n”, ch, count);
}
Do'stlaringiz bilan baham: |