Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
krkris
/
Loogikafunktsioon
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
58d71dc7
authored
Apr 10, 2022
by
erfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lihtimplikantide leidmise koodi lisandused
parent
e94f9aff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
53 deletions
Kood.c
Kood.c
View file @
58d71dc7
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
// kood kommenteerida, muutujate nimed, funktsioonide lisamine
typedef
struct
{
typedef
struct
{
char
kood
[
5
];
char
kood
[
5
];
int
indeks
;
int
indeks
;
}
implikandid
;
}
implikandid
;
// kleepimata implikandid
typedef
struct
{
typedef
struct
{
char
kood
[
5
];
char
kood
[
5
];
int
indeks
;
int
indeks
;
}
implikandid2
;
}
implikandid2
;
// 1.kleepimise tulemus
typedef
struct
{
char
kood
[
5
];
int
indeks
;
}
implikandid3
;
// 2.kleepimise tulemus
// Kasutaja sisestatu kontrollimine:
int
kontroll
(
char
a
[
16
]){
int
kontroll
(
char
a
[
16
]){
int
i
;
int
i
;
for
(
i
=
0
;
i
<
strlen
(
a
);
i
++
){
for
(
i
=
0
;
i
<
strlen
(
a
);
i
++
){
...
@@ -26,6 +34,8 @@ int kontroll(char a[16]){
...
@@ -26,6 +34,8 @@ int kontroll(char a[16]){
return
0
;
return
0
;
}
}
// Kasutaja loogikaväärtuste sisestus:
int
sisestus
(
const
char
tekst
[
40
],
char
a
[
16
],
char
b
[
16
],
char
c
[
16
],
char
d
[
16
]){
int
sisestus
(
const
char
tekst
[
40
],
char
a
[
16
],
char
b
[
16
],
char
c
[
16
],
char
d
[
16
]){
int
i
;
int
i
;
printf
(
"%s"
,
tekst
);
printf
(
"%s"
,
tekst
);
...
@@ -99,24 +109,10 @@ int sisestus(const char tekst[40], char a[16], char b[16], char c[16], char d[16
...
@@ -99,24 +109,10 @@ int sisestus(const char tekst[40], char a[16], char b[16], char c[16], char d[16
return
0
;
return
0
;
}
}
void
info
(
char
a
[
16
],
char
b
[
16
],
char
c
[
16
],
char
d
[
16
]){
char
f0
;
char
f1
;
char
f2
;
char
f3
;
char
f4
;
char
f5
;
char
f6
;
char
f7
;
char
f8
;
char
f9
;
char
fA
;
char
fB
;
char
fC
;
char
fD
;
char
fE
;
char
fF
;
// Reed-Mulleri polünoomi kujul oleva loogikafunktsiooni kohta info andmine:
void
info
(
char
a
[
16
],
char
b
[
16
],
char
c
[
16
],
char
d
[
16
],
char
f0
,
char
f1
,
char
f2
,
char
f3
,
char
f4
,
char
f5
,
char
f6
,
char
f7
,
char
f8
,
char
f9
,
char
fA
,
char
fB
,
char
fC
,
char
fD
,
char
fE
,
char
fF
){
//char f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fA, fB, fC, fD, fE, fF;
if
(
strlen
(
a
)
>=
16
){
if
(
strlen
(
a
)
>=
16
){
f0
=
a
[
0
];
f0
=
a
[
0
];
...
@@ -226,19 +222,17 @@ void info(char a[16], char b[16], char c[16], char d[16]){
...
@@ -226,19 +222,17 @@ void info(char a[16], char b[16], char c[16], char d[16]){
}
}
else
{
else
{
printf
(
"ilma [x4] PAARIS
\n
"
);
printf
(
"ilma [x4] PAARIS
\n
"
);
}
}
// info funktsiooni lõpp siin
}
// Kontuuride leidmine
void
kontuur
(
char
f0
,
char
f1
,
char
f2
,
char
f3
,
char
f4
,
char
f5
,
char
f6
,
char
f7
,
char
f8
,
char
f9
,
char
fA
,
char
fB
,
char
fC
,
char
fD
,
char
fE
,
char
fF
){
implikandid
implikant
[
16
];
implikandid
implikant
[
16
];
int
i
=
0
;
int
i
=
0
;
int
arv
=
0
;
int
j
,
k
;
int
j
,
k
;
/*char array[16] = {f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fA, fB, fC, fD, fE, fF};
for(i = 0; i<16; i++){
if(array[i] == '1'){
arv++;
}
}*/
if
(
f0
==
'1'
){
if
(
f0
==
'1'
){
strcpy
(
implikant
[
i
].
kood
,
"0000"
);
strcpy
(
implikant
[
i
].
kood
,
"0000"
);
...
@@ -336,69 +330,151 @@ void info(char a[16], char b[16], char c[16], char d[16]){
...
@@ -336,69 +330,151 @@ void info(char a[16], char b[16], char c[16], char d[16]){
implikant
[
i
].
indeks
=
4
;
implikant
[
i
].
indeks
=
4
;
i
++
;
i
++
;
}
}
printf
(
"
\n
"
);
printf
(
"Indeksid:"
);
// indeksite test
printf
(
"%s
\n
"
,
implikant
[
0
].
kood
);
for
(
j
=
0
;
j
<
i
;
j
++
){
for
(
j
=
0
;
j
<
i
;
j
++
){
printf
(
"%d
\n
"
,
implikant
[
j
].
indeks
);
printf
(
"%d
\n
"
,
implikant
[
j
].
indeks
);
}
}
int
eri
=
0
;
int
eri
=
0
;
implikandid2
implikant2
[
16
];
implikandid2
implikant2
[
16
];
int
q
;
int
q
;
char
arr
[
5
];
int
t
=
0
;
int
t
=
0
;
for
(
j
=
0
;
j
<
i
;
j
++
){
for
(
k
=
0
;
k
<
i
;
k
++
){
for
(
j
=
0
;
j
<
i
;
j
++
){
if
(
implikant
[
i
].
indeks
-
implikant
[
k
].
indeks
==
1
||
implikant
[
i
].
indeks
-
implikant
[
k
].
indeks
==
-
1
){
for
(
k
=
0
;
k
<
i
;
k
++
){
if
(
implikant
[
i
].
kood
[
0
]
!=
implikant
[
k
].
kood
[
0
]){
if
(
implikant
[
j
].
indeks
-
implikant
[
k
].
indeks
==
1
||
implikant
[
j
].
indeks
-
implikant
[
k
].
indeks
==
-
1
){
if
(
implikant
[
j
].
kood
[
0
]
!=
implikant
[
k
].
kood
[
0
]){
eri
++
;
eri
++
;
q
=
0
;
q
=
0
;
}
}
if
(
implikant
[
i
].
kood
[
1
]
!=
implikant
[
k
].
kood
[
1
]){
if
(
implikant
[
j
].
kood
[
1
]
!=
implikant
[
k
].
kood
[
1
]){
eri
++
;
eri
++
;
q
=
1
;
q
=
1
;
}
}
if
(
implikant
[
i
].
kood
[
2
]
!=
implikant
[
k
].
kood
[
2
]){
if
(
implikant
[
j
].
kood
[
2
]
!=
implikant
[
k
].
kood
[
2
]){
eri
++
;
eri
++
;
q
=
2
;
q
=
2
;
}
}
if
(
implikant
[
i
].
kood
[
3
]
!=
implikant
[
k
].
kood
[
3
]){
if
(
implikant
[
j
].
kood
[
3
]
!=
implikant
[
k
].
kood
[
3
]){
eri
++
;
eri
++
;
q
=
3
;
q
=
3
;
}
}
if
(
eri
==
1
){
if
(
eri
==
1
){
strcpy
(
implikant2
[
0
].
kood
,
implikant
[
i
].
kood
);
if
(
q
==
0
){
printf
(
"%s"
,
implikant2
[
0
].
kood
);
strcpy
(
implikant2
[
t
].
kood
,
implikant
[
j
].
kood
);
// des, source
/*printf("\n");
implikant2
[
t
].
kood
[
q
]
=
'-'
;
arr[0] = '-';
printf
(
"%s
\n
"
,
implikant2
[
t
].
kood
);
arr[1] = implikant[i].kood[1];
}
arr[2] = implikant[i].kood[2];
if
(
q
==
1
){
arr[3] = implikant[i].kood[3];
strcpy
(
implikant2
[
t
].
kood
,
implikant
[
j
].
kood
);
printf("%s", arr);*/
implikant2
[
t
].
kood
[
q
]
=
'-'
;
/*if(q == 0){
printf
(
"%s
\n
"
,
implikant2
[
t
].
kood
);
implikant2[t].kood[0] = '-';
}
if
(
q
==
2
){
strcpy
(
implikant2
[
t
].
kood
,
implikant
[
j
].
kood
);
implikant2
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant2
[
t
].
kood
);
}
if
(
q
==
3
){
strcpy
(
implikant2
[
t
].
kood
,
implikant
[
j
].
kood
);
implikant2
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant2
[
t
].
kood
);
}
}
t++;*/
t
++
;
}
}
eri
=
0
;
}
}
}
}
}
}
}
int
uhtedeArv
;
for
(
j
=
0
;
j
<
t
;
j
++
){
uhtedeArv
=
0
;
if
(
implikant2
[
j
].
kood
[
0
]
==
'1'
){
uhtedeArv
++
;
}
if
(
implikant2
[
j
].
kood
[
1
]
==
'1'
){
uhtedeArv
++
;
}
if
(
implikant2
[
j
].
kood
[
2
]
==
'2'
){
uhtedeArv
++
;
}
if
(
implikant2
[
j
].
kood
[
3
]
==
'3'
){
uhtedeArv
++
;
}
implikant2
[
j
].
indeks
=
uhtedeArv
;
}
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
implikandid3
implikant3
[
16
];
t
=
0
;
for
(
j
=
0
;
j
<
i
;
j
++
){
for
(
k
=
0
;
k
<
i
;
k
++
){
if
(
implikant2
[
j
].
indeks
-
implikant2
[
k
].
indeks
==
1
||
implikant2
[
j
].
indeks
-
implikant2
[
k
].
indeks
==
-
1
){
if
(
implikant2
[
j
].
kood
[
0
]
!=
implikant2
[
k
].
kood
[
0
]){
eri
++
;
q
=
0
;
}
if
(
implikant2
[
j
].
kood
[
1
]
!=
implikant2
[
k
].
kood
[
1
]){
eri
++
;
q
=
1
;
}
if
(
implikant2
[
j
].
kood
[
2
]
!=
implikant2
[
k
].
kood
[
2
]){
eri
++
;
q
=
2
;
}
if
(
implikant2
[
j
].
kood
[
3
]
!=
implikant2
[
k
].
kood
[
3
]){
eri
++
;
q
=
3
;
}
if
(
eri
==
1
){
if
(
q
==
0
){
strcpy
(
implikant3
[
t
].
kood
,
implikant2
[
j
].
kood
);
// des, source
implikant3
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant3
[
t
].
kood
);
}
if
(
q
==
1
){
strcpy
(
implikant3
[
t
].
kood
,
implikant2
[
j
].
kood
);
implikant3
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant3
[
t
].
kood
);
}
if
(
q
==
2
){
strcpy
(
implikant3
[
t
].
kood
,
implikant2
[
j
].
kood
);
implikant3
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant3
[
t
].
kood
);
}
if
(
q
==
3
){
strcpy
(
implikant3
[
t
].
kood
,
implikant2
[
j
].
kood
);
implikant3
[
t
].
kood
[
q
]
=
'-'
;
printf
(
"%s
\n
"
,
implikant3
[
t
].
kood
);
}
t
++
;
}
eri
=
0
;
}
}
}
}
int
main
(
void
){
int
main
(
void
){
char
a
[
16
],
b
[
16
],
c
[
16
],
d
[
16
];
char
a
[
16
],
b
[
16
],
c
[
16
],
d
[
16
];
char
f0
,
f1
,
f2
,
f3
,
f4
,
f5
,
f6
,
f7
,
f8
,
f9
,
fA
,
fB
,
fC
,
fD
,
fE
,
fF
;
int
input
;
int
input
;
input
=
sisestus
(
"Sisestage 4x4 Karnaugh kaart voi 16 loogikavaartust:
\n
"
,
a
,
b
,
c
,
d
);
input
=
sisestus
(
"Sisestage 4x4 Karnaugh kaart voi 16 loogikavaartust:
\n
"
,
a
,
b
,
c
,
d
);
if
(
input
==
1
){
if
(
input
==
1
){
return
1
;
return
1
;
}
}
info
(
a
,
b
,
c
,
d
);
info
(
a
,
b
,
c
,
d
,
f0
,
f1
,
f2
,
f3
,
f4
,
f5
,
f6
,
f7
,
f8
,
f9
,
fA
,
fB
,
fC
,
fD
,
fE
,
fF
);
kontuur
(
f0
,
f1
,
f2
,
f3
,
f4
,
f5
,
f6
,
f7
,
f8
,
f9
,
fA
,
fB
,
fC
,
fD
,
fE
,
fF
);
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment