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