Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C Program to construct a DFA which accepts L = {aN | N ≥ 1}
Let us take a string S of size N, we have to design a Deterministic Finite Automata (DFA) for accepting the language L = {aN | N ≥ 1}.
The string accepting the language L is {a, aa, aaa, aaaaaaa…, }.
Now the user has to enter a string, if that string is present in the given language, then print “entered string is Accepted”. Otherwise, print “entered string is not Accepted”.
DFA transition diagram for the given language is −

Example
Following is the C program to construct DFA which accepts the language L = {aN | N ≥ 1} −
#includeint main() { char S[30]; int l,i; int count = 0; printf("To implement DFA of language {aN | N ≥ 1}
enter input string:"); scanf("%s",S); l=strlen(S); for (i=0;iOutput
You will get the following output −
Run 1: To implement DFA of language {aN | N >= 1} enter input string:aaaa entered string is accepted Run 2: To implement DFA of language {aN | N >= 1} enter input string:badsaa entered string is NOT ACCEPTED
Advertisements
