You are on page 1of 2

Program 1 (Font – Arial, Size- 16)

AIM: Write a program in C to implement DFA which accept strings of {a,b} and
having substring ‘abb’. (Font-Times New Roman, Size-14)

#include<stdio.h> (Font-Times New Roman, Size-12)


#include<conio.h>
int state=0;
void strmatch(char);
void main()
{
char str[50], a;
int i, b;
clrscr();
printf("\n\nName\t\t:\t XYZ\n");
printf("Roll number\t:\t 12345678\n");
printf("Enter the string\n");
gets(str);
for(i=0;str[i]!='\0' ;i++)
{
strmatch(str[i]);
}
if(state==3)
printf("string is accepted" );
else
printf("string not is accepted" );
getch();
}
void strmatch(char ch)
{
switch(state)
{
case 0: if(ch=='a')
state=1;
else if(ch=='b')
state=0;
else
state=4;
break;
case 1: if(ch=='a')
state=1;
else if(ch=='b')
state=2;
else
state=4;
break;
case 2: if(ch=='a')
state=1;
else if(ch=='b')
state=3;
else
state=4;
break;
case 3: if(ch=='a'|| ch=='b')
state=3;
else
state=4;
break;
}
}

Output:

You might also like