-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_1_end_0.c
47 lines (37 loc) · 1.2 KB
/
start_1_end_0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <string.h>
#define MAX 100
//DFA that accepts strings starting with 1 and ending with 0
int main() {
int i;
char str[MAX], f = 'A', response;
do {
printf("Enter string (0 or 1): ");
scanf("%s", str);
for (i = 0; i < strlen(str); i++) {
switch(f)
{
case 'A':
if(str[i] == '0') f = 'D';
else if(str[i] == '1') f = 'B';
break;
case 'B':
if(str[i] == '0') f = 'C';
else if(str[i] == '1') f = 'B';
break;
case 'C':
if(str[i] == '0') f = 'C';
else if(str[i] == '1') f = 'B';
break;
case 'D':
if(str[i] == '0') f = 'D';
else if(str[i] == '1') f = 'D';
break;
}
}
if (f == 'C') printf("Accepted \n");
else printf("Rejected \n");
printf("Do you want to continue(y/n): ");
scanf("%s", &response);
} while(response == 'y');
}