A word is considered elfish if it contains the letters: e, l, and f in it, in any order.
For example, we would say that the following words are elfish: white leaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a recursive function called elfish? that, given a word, tells us if that word is elfish or not
Program:For example, we would say that the following words are elfish: white leaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a recursive function called elfish? that, given a word, tells us if that word is elfish or not
#include <stdio.h>
#include <string.h>
int elfish(char *s,char *b, int i)
{
if(b[i]=='\0')
return 1;
if(strchr(s,b[i]))
return elfish(s,b,i+1);
else
return 0;
}
main()
{
char s[100],b[4]="elf";
int result;
printf("enter the string\n");
gets(s);
result=elfish(s,b,0);
if(result ==0)
printf("given string is not elfish");
else
printf("given string is elfish");
}
#include <string.h>
int elfish(char *s,char *b, int i)
{
if(b[i]=='\0')
return 1;
if(strchr(s,b[i]))
return elfish(s,b,i+1);
else
return 0;
}
main()
{
char s[100],b[4]="elf";
int result;
printf("enter the string\n");
gets(s);
result=elfish(s,b,0);
if(result ==0)
printf("given string is not elfish");
else
printf("given string is elfish");
}
Output:
nice program madam
ReplyDelete