Untitled

 avatar
unknown
plain_text
a year ago
883 B
1
Indexable
#include<stdio.h>
#include<string.h>

int main() {
    int table[2][2], i, j, status = 0;
    char input[100];

    printf("To implement DFA of language (a+aa*b)* Enter input string\n");
    table[0][0] = 1;
    table[0][1] = 1;
    table[1][0] = 1;
    table[1][1] = 0;

    scanf("%s", input);
    j = strlen(input);

    for (i = 0; i < j; i++) {
        if (input[i] != 'a' && input[i] != 'b') {
            printf("The entered value is wrong\n");
            return 0;
        }

        if (input[i] == 'a')
            status = table[status][0];
        else
            status = table[status][1];

        if (status == -1) {
            printf("String not accepted\n");
            return 0;
        }
    }

    if (status == 1)
        printf("String accepted\n");
    else
        printf("String not accepted\n");

    return 0;
}
Leave a Comment