Computer Science, asked by cibi6964, 1 year ago

Write a c program to recognize strings under 'a*' 'a*b+' 'ab'

Answers

Answered by Yagnik11
7
a C program to recognise strings under 'a*' 'a*b+' 'ab' is JABA
Answered by greeshmakachirayil
0

Answer:

C program to recognize strings under 'a*' 'a*b+' 'ab':

main void ()

{

int s[20],c;

state=0 and i=0;

clrscr();

Insert a string here: printf("n");

gets(s);

while(s[i]!='\0')

{

switch(state)

{

c=s[i++] in case 0;

if(c=='a')

state=1;

if (c=='b') then

state=2;

else

state=6;

break;

instance 1: c=s[i++];

if(c=='a')

state=3;

if (c=='b') then

state=4;

else

state=6;

break;

instance 2: c=s[i++];

if(c=='a')

state=6;

if (c=='b') then

state=2;

else

state=6;

break;

c=s[i++] in instance 3.

if(c=='a')

state=3;

if (c=='b') then

state=2;

else

state=6;

break;

c=s[i++] in instance 4.

if(c=='a')

state=6;

if (c=='b') then

state=5;

else

state=6;

break;

c=s[i++] in instance 5.

if(c=='a')

state=6;

if (c=='b') then

state=2;

else

state=6;

break;

Case 6 is as follows: printf("n%s is not recognized. ",s);

exit(0);

}

}

if(state==1)

"%s is acceptable under rule 'a'," printed;

If (state==2)||(state==4)) then

"n%s is acceptable under rule 'a*b+'",s", printf;

If (state==5), then

"%s is acceptable under rule 'ab'," printf(s);

getch();

}

Learn more about strings here:

https://brainly.in/question/2521714

Learn more about operations on strings here:

https://brainly.in/question/6012159

Similar questions