Created
March 5, 2018 19:09
-
-
Save gallirohik/c2079a91efbc601341eb432e2f6cd35f to your computer and use it in GitHub Desktop.
finding the pair in the given string(two letters are said to be pair,if they are eqal and have a charecter in between them).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int len(char *str) | |
| { | |
| int c=0; | |
| while(*str++!='\0') | |
| c++; | |
| return c; | |
| } | |
| int count_pair(char *str,int n) | |
| { | |
| if(n<2) | |
| return 0; | |
| if(*str==*(str+2)) | |
| return 1+count_pair(str+1,--n); | |
| else | |
| return 0+count_pair(str+1,--n); | |
| } | |
| int main() | |
| { | |
| char *str; | |
| int n; | |
| str=(char*)malloc(50*sizeof(char)); | |
| scanf("%s",str); | |
| printf("%d",count_pair(str,len(str))); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment