Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
832 B
3
Indexable
#include <stdio.h>

int startsWithA(const char *str) {
    // Initial state (q0)
    if (str[0] == '\0') {
        // If the string is empty, it does not start with 'a'
        return 0;
    }

    // Transition from state q0 to state q1 if the first character is 'a'
    if (str[0] == 'a') {
        // If the first character is 'a', the string is accepted
        return 1;
    } else {
        // If the first character is not 'a', the string is rejected
        return 0;
    }
}

int main() {
    char input[100];

    // Prompt the user to enter a string
    printf("Enter a string: ");
    scanf("%s", input);

    // Check if the string starts with 'a'
    if (startsWithA(input)) {
        printf("The string starts with 'a'.\n");
    } else {
        printf("The string does not start with 'a'.\n");
    }

    return 0;
}
Leave a Comment