
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Program to build DFA that starts and ends with ‘a’ from the input (a, b)
DFA stands for Deterministic Finite Automata. It is a finite state machine that accepts or a string based on its acceptor.
Here, we are going to make a DFA that accepts a string that starts and ends with a. The input is from the set (a,b). Based on this we will design a DFA. Now, Let's discuss some valid and invalid cases that are accepted by a DFA.
Strings that are accepted by DFA: ababba, aabba, aa, a.
Strings that are not accepted by DFA: ab, b, aabab.
Example
This program check for a string that starts and ends with a. This DFA will accept all strings that starts and ends with a. The code checks for first and last elements equality and rest everything in between is possible from (a,b).
#include <iostream> #include <string.h> using namespace std; int main(){ char str[] = {"ababba"}; int lenght = strlen(str); if(str[0] == 'a' && str[lenght-1] == 'a'){ printf("Accepted"); else{ printf("Rejected"); return 0; } } }
Output
Accepted
- Related Articles
- Program to build DFA that starts and end with ‘a’ from input (a, b) in C++
- Write a program in C++ to count the Number of substrings that starts with ‘1’ and ends with ‘1’
- C Program to build DFA accepting the languages ending with “01â€
- Count substrings that starts with character X and ends with character Y in C++
- Python - Check whether a string starts and ends with the same character or not
- Find if a string starts and ends with another given string in C++
- Program to construct DFA for Regular Expression C( A + B)+
- C Program to construct DFA for Regular Expression (a+aa*b)*
- Maximum length palindromic substring for every index such that it starts and ends at that index
- PHP script to get all keys from an array that starts with a certain string
- Golang Program to check a string starts with a specified substring
- Swift Program to check a string starts with a specified substring
- How to determine if an input string ends with a specified suffix in JSP?
- C program to remove the brackets from a given input.
- In a soap micelle, the soap molecules are arranged radially with:(a) ionic ends directed towards the centre and hydrocarbon ends directed outwards (b) hydrocarbon ends directed towards the centre and ionic ends directed outwards (c) both ionic ends and hydrocarbon ends directed toward the centre (d) both hydrocarbon ends and ionic ends directed outwards

Advertisements