Question

Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers...

Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers // 0000001, 101, 11111, etc. It must return accepted or rejected(HAVE TO SHOW EACH STATE AS A FUNCTION,Q0 AND Q1. CANNOT USE STRINGS OR LENGTH OF STRING) not the same posted problem

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main()
{
int i = 0;
char c;
printf("Enter Input:");
while ((c = getchar()) != '\n')
{ // read a line char by char
if ( c!='0' && c!='1')
{
    printf("Invalid Input \n");
    return 0;
}

printf("The value at state q%u\n is %c\n",i, c);
i++;
}
if(i%2 != 0)
{
printf("The string is accepted");
   
}
else
{
printf("The string is Rejected");
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT