DFA
#include<stdio.h> int main(){ int i=0,state=0; char str[100]; printf("\nEnter the string:- "); gets(str); while(str[i]!='\0'){ switch(str[i]){ case 'a':state=1; break; case 'b':if(state!=0) state=(state+1)%4; break; default:state=5; i=strlen(str)-1; } i++; } if(state==3) printf("\nValid String\n"); else printf("\nIn Valid String\n"); return 0; }
No comments:
Post a Comment