Untitled
unknown
plain_text
a year ago
1.2 kB
6
Indexable
#include<stdio.h> #include<string.h> #include<stdlib.h> void main() { char s[20],c; int state=0,i=0; printf("Enter a string:"); scanf("%s",s); while(s[i]!="\0") { switch(state) { case 0: c=s[i++]; if(c=='a') state=1; else state=4; break; case 1: c=s[i++]; if(c=='a') state=1; else if(c=='b') state=2; else state=4; break; case 2: c=s[i++]; if(c=='b') state=3; else state=4; break; case 3: if((c=s[i++])!='\0') state 4; break; case 4:printf("\n %s the string is not recognized",s); exit(0); } } if(state==1) printf("\n %s is accepted under the rule 'a'",s); else if(state==2) printf("\n %s is accepted under the rule 'ab'",s); else if(state==1) printf("\n %s is accepted under the rule 'abb'",s); else printf("\n %s the is not recognized",s); }
Editor is loading...
Leave a Comment