Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int is_palindrome(int start, int end, char *str)
- {
- if (start>=end)
- return 1;
- if (str[start]!= str[end])
- return 0;
- return is_palindrome(++start,--end,str);
- }
- int frequency(int end, char *str, char c)
- {
- int fr=0;
- int i;
- for(i=0;i<end;i++)
- if(str[i]==c)
- fr+=1;
- return fr;
- }
- int main()
- {
- char str[20],c;
- printf("Enter the String.\n");
- fgets( str, sizeof( str ), stdin );
- if(is_palindrome(0, strlen(str)-2, str))
- printf("It's a palindrome!\n");
- else
- printf("It's not a palindrome! \n");
- printf("Enter the character you want to search for: ");
- scanf("%c",&c);
- printf("The frequency is %d",frequency((strlen(str)-1),str,c));
- return 0;
- }
- //Output
- //Enter the String.
- //ABBA
- //It's a palindrome!
- //Enter the character you want to search for: A
- //The frequency is 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement