Skip to content

Instantly share code, notes, and snippets.

@gallirohik
Created March 5, 2018 19:09
Show Gist options
  • Select an option

  • Save gallirohik/c2079a91efbc601341eb432e2f6cd35f to your computer and use it in GitHub Desktop.

Select an option

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).
#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