(a+b)*abb write a program in c++
Answers
Answered by
2
Explanation:
Program in C for DFA accepting string "abb"
/*prog for DFA accepting string abb*/
#include<stdio.h>
void main()
{
int initial_state=1,len,current_state=1;
char a,b,str[10];
clrscr();
printf("Enter string : ");
scanf("%s",&str);
len=strlen(str);
if(len==3){ /*here d length of string is checked*/
{
if(initial_state==1 && str[0]=='a'){ /*to accept first element a*/
current_state=2;
}
else {
printf("String is Rejected.");
exit(0);}
}
{
if(current_state==2 && str[1]=='b'){ /*to accept second element b*/
current_state=3;
}
else {
printf("String is Rejected.");
exit(0);}
}
{
if(current_state==3 && str[2]=='b'){ /*to accept third element b*/
current_state=4;
printf(" String is accepted");}
else {
printf("String is rejected.");
exit(0);}
}
}
else{
printf("Enter correct string." ); /*if length & character of string is not correct*/
exit(0);
}
getch();
}
please mark me as brainliast
Answered by
0
Explanation:
sjekffdkkffkkdkjddr
soory sorry
Similar questions