#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string\n");
gets(string);
while ( string[c] != '\0' )
{
/* Considering characters from 'a' to 'z' only */
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] !=0 ){
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
if(2*count[c]==strlen(string)) {
printf("%c occurs %d times in the entered string of size of %d character.\n",c+'a',count[c],strlen(string));
break;
}
}
}
if(c==26)
printf("\nNo");
else
printf("yes and character is %c",c+'a');
return 0;
}
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string\n");
gets(string);
while ( string[c] != '\0' )
{
/* Considering characters from 'a' to 'z' only */
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] !=0 ){
printf("%c occurs %d times in the entered string.\n",c+'a',count[c]);
if(2*count[c]==strlen(string)) {
printf("%c occurs %d times in the entered string of size of %d character.\n",c+'a',count[c],strlen(string));
break;
}
}
}
if(c==26)
printf("\nNo");
else
printf("yes and character is %c",c+'a');
return 0;
}
Helpful post, thanks for sharing this coding. It is really helpful. Keep up the good work and share more.
ReplyDeleteC++ Training | C Language Training
Hello, First I want to thank for the example that is being very useful for some studies that I am doing.
ReplyDeleteC and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery