Problem statement
Write a c program to check weather two given strings are equal or not using recursion
int compair(char str1[],char str2[]);
int main()
{
char str1[20],str2[30];
int y;
printf("enter string 1 ");
scanf("%s",str1);
printf("enter string 2 ");
scanf("%s",str2);
y=compair(str1,str2);
if(y==1)
{
printf("strings arte same \n");
}
else
{
printf("string are different \n");
}
return 0;
}
int compair(char str1[],char str2[])
{
if(*str1!=*str2)
{
return 0;
}
if(*str2=='\0'&&*str1=='\0')
{
return 1;
}
else if(*str1==*str2)
{
return compair(str1+1,str2+1);
}
}
No comments:
Post a Comment