Untitled
unknown
plain_text
2 years ago
1.1 kB
3
Indexable
#include<stdio.h> #include<string.h> void DFA(char[]); int main() { char str[50]; printf("Enter the string that is to be checked\n"); scanf("%s",str); DFA(str); } void DFA(char str[]) { int cstate=0; for(int i=0;i<strlen(str);i++) { if(cstate==0) { if(str[i]=='a') { cstate=1; } else { cstate=0; } } else if(cstate==1) { if(str[i]=='a') { cstate=2; } else { cstate=0; } } else if(cstate==2) { if(str[i]=='a'||str[i]=='b') { cstate=2; } } } if(cstate==2) { printf("The string is accepted\n"); } else { printf("The string is not accepted\n"); } }
Editor is loading...