0% found this document useful (0 votes)
25 views2 pages

Nfa 1

The document provides code for a C program that simulates a non-deterministic finite automaton (N DFA) for a given language. The program defines states and transitions between states based on input symbols. It checks the input string against the transition table and states to determine if the string is accepted or rejected by the N DFA.

Uploaded by

siddardtha666666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Nfa 1

The document provides code for a C program that simulates a non-deterministic finite automaton (N DFA) for a given language. The program defines states and transitions between states based on input symbols. It checks the input string against the transition table and states to determine if the string is accepted or rejected by the N DFA.

Uploaded by

siddardtha666666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

2.write a c program to simulate a non-dfa for given language.

program:

#include <string.h>

#define NUM_STATES 2

#define ALPHABET_SIZE 2

int transition[NUM_STATES][ALPHABET_SIZE] = {

{0, 1},

{0, 1}

};

int initialState = 0;

int acceptingStates[] = {0};\

bool isAcceptingState(int state) {

for (int i = 0; i < sizeof(acceptingStates) / sizeof(acceptingStates[0]); i++) {

if (state == acceptingStates[i]) {

return true;

return false;

int main() {

char input[100];

printf("Enter an input string (0s and 1s): ");

scanf("%s", input);

int currentState = initialState;

int inputLength = strlen(input);

for (int i = 0; i < inputLength; i++) {

char symbol = input[i];

int symbolIndex = symbol - '0';

if (symbolIndex < 0 || symbolIndex >= ALPHABET_SIZE) {


printf("Invalid symbol in the input string: %c\n", symbol);

return 1;

currentState = transition[currentState][symbolIndex];

if (isAcceptingState(currentState)) {

printf("Accepted\n");

} else {

printf("Rejected\n");

return 0;

output:

You might also like