- #include <stdio.h>
- #include <string.h>
- void main() {
- int table[7][2], i, l, status = 0;
- char input[100];
- printf("To implement DFA of language (01)^*(21)^+(0/1)^*2\nEnter Input String: ");
- // Transition table initialization
- for (int j = 0; j < 7; j++) {
- for (int k = 0; k < 2; k++) {
- table[j][k] = -1; // Initialize to invalid state
- }
- }
- // Transition definitions
- table[0][0] = 1; // Transition from state 0 to state 1 on input '0'
- table[1][1] = 2; // Transition from state 1 to state 2 on input '1'
- table[2][0] = 3; // Transition from state 2 to state 3 on input '0'
- table[3][1] = 4; // Transition from state 3 to state 4 on input '1'
- table[4][0] = 5; // Transition from state 4 to state 5 on input '0'
- table[4][1] = 6; // Transition from state 4 to state 6 on input '1'
- table[5][0] = 5; // Transition from state 5 to state 5 on input '0'
- table[5][1] = 6; // Transition from state 5 to state 6 on input '1'
- table[6][0] = 5; // Transition from state 6 to state 5 on input '0'
- table[6][1] = 6; // Transition from state 6 to state 6 on input '1'
- scanf("%s", input);
- l = strlen(input);
- for (i = 0; i < l; i++) {
- if (input[i] != '0' && input[i] != '1') {
- printf("Invalid input symbol: %c\n", input[i]);
- return;
- }
- int symbolIndex = input[i] - '0'; // Convert char to int ('0' -> 0, '1' -> 1)
- status = table[status][symbolIndex];
- if (status == -1) {
- printf("String not Accepted\n");
- return;
- }
- }
- if (status == 2 || status == 3 || status == 5) {
- printf("String Accepted\n");
- } else {
- printf("String not Accepted\n");
- }
- }
[text] Sambhav-ans-1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: