Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » ParsingRSS Feeds

Program to display DFA

Posted By: Logan Evans     Category: C++ Programming     Views: 12743

Program to display DFA i.e design for assembly

Code for Program to display DFA in C++ Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{

    int i=0,f=0,s=0;
    char arr[80];

    printf("Enter any input string terminated by $:");
    scanf("%s",arr);

    while(arr[i]!='$' && f==0)
    {
        switch(s)
        {
            case 0:
                if(arr[i] >='0' && arr[i] <='9')
                {
                    s=1;
                    i++;
                }
                else

                    f=1;
                    break;

            case 1:
                 if(arr[i] >='0' && arr[i] <='9')
                 i++;
                 elseif(arr[i]=='.')
                 {
                 s=2;
                 i++;
                 }
                 else
                 f=1;
                 break;

            case 2:
                if(arr[i] >='0' && arr[i] <='9')
                {
                    s=3;
                    i++;
                }
                else
                    f=1;
                    break;
              case 3:
                 if(arr[i] >='0' && arr[i] <='9')
                 i++;
                 elseif(arr[i]=='E' || 'e')
                 {
                 s=4;
                 i++;
                 }
                 else
                 f=1;
                 break;
            case 4:
                if(arr[i] == '+' || arr[i] == '-')
                {
                s=5;
                i++;
                }
                else
                f=1;
                break;

            case 5: if(arr[i] >='0' && arr[i] <='9')
                i++;
                else
                f=1;
                break;

        }

    }
      if(f==1)
    printf("\nInvalid String !");
      else
    printf("String is Valid ");

getch();
}




OUTPUT
***********
Enter any input string terminated by $:12.12E+12$
String is Valid

Enter any input string terminated by $:10.12E15$
Invalid String !




[/Code]
  
Share: 


Didn't find what you were looking for? Find more on Program to display DFA Or get search suggestion and latest updates.

Logan Evans
Logan Evans author of Program to display DFA is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!