-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFA.c
63 lines (54 loc) · 1.77 KB
/
DFA.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include<string.h>
int c=0;
void binary(int n, int arr[], int i)
{
if(n==i)
{
int one=0;
int zero=0;
for(int j=0;j<n;j++)
{
if(arr[j]==0){
zero++;
}
else{
one++;
}
}
if(one%2==0 && zero%2==0 && one>0 && zero>0) // condition - only strings with even no of 0s and even no of 1s are allowed
{
c++;
for(int j=0;j<n;j++)
{
printf("%d",arr[j]);
}
printf("\n");
}
return;
}
arr[i]=0;
binary(n,arr,i+1);
arr[i]=1;
binary(n,arr,i+1);
}
int main()
{
int l,arr[20];
scanf("%d",&l);
binary(l,arr,0);
printf("\n Total number of accepted states: %d",c);
return 0;
}
/*
input:
4
output:
0011
0101
0110
1001
1010
1100
Total number of accepted states: 6
*/