Commit ca4286ed by erfeld

Update Kood.c

parent c1342a4c
Showing with 185 additions and 45 deletions
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
int sisestus(const char[], char[], char[], char[], char[]); int kontroll(char a[16]){
int i;
for (i = 0; i < strlen(a); i++){
if (a[i] != '0' && a[i] != '1'){
int main(void){ printf("Lubamatu sisend: %s\n", a);
char a[20], b[20], c[20], d[20]; return 1;
int x; }
x = sisestus("Sisestage 4x4 Karnaugh kaart või 16 loogikaväärtust: \n", a, b, c, d); }
if (x == 1){ if (strlen(a) != 4){
printf("Lubamatu sisend %s\n", a);
return 1; return 1;
} }
return 0; return 0;
} }
int sisestus(const char tekst[40], char a[20], char b[20], char c[20], char d[20]){ 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);
scanf("%s", a); scanf("%s", a);
if (strlen(a) == 4){
for (i = 0; i < strlen(a); i++){ for (i = 0; i < strlen(a); i++){
if (a[i] != '0' && a[i] != '1'){ if (a[i] != '0' && a[i] != '1'){
printf("Lubamatu sisend: %s", a); printf("Lubamatu sisend: %s\n", a);
return 1; return 1;
} }
} }
if (strlen(a) == 4){
do{
printf("\n%s\n", a); printf("\n%s\n", a);
printf("Sisestage teine rida \n"); printf("Sisestage K-kaardi TEINE rida \n");
scanf("%s", b); scanf("%s", b);
if (strlen(b) != 4){ }while(kontroll(b) == 1);
printf("Vale!"); do{
}
for (i = 0; i < strlen(b); i++){
if (b[i] != '0' && b[i] != '1'){
printf("Lubamatu sisend: %s", b);
return 1;
}
}
printf("\n%s\n", a); printf("\n%s\n", a);
printf("%s\n", b); printf("%s\n", b);
printf("Sisestage kolmas rida \n"); printf("Sisestage K-kaardi KOLMAS rida \n");
scanf("%s", c); scanf("%s", c);
if (strlen(c) != 4){ }while(kontroll(c) == 1);
printf("Vale!"); printf("\n%s\n", a);
} printf("%s\n", b);
for (i = 0; i < strlen(c); i++){ printf("%s\n", c);
if (c[i] != '0' && c[i] != '1'){ do{
printf("Lubamatu sisend: %s", c);
return 1;
}
}
printf("\n%s\n", a); printf("\n%s\n", a);
printf("%s\n", b); printf("%s\n", b);
printf("%s\n", c); printf("%s\n", c);
printf("Sisestage neljas rida \n"); printf("Sisestage K-kaardi NELJAS rida \n");
scanf("%s", d); scanf("%s", d);
if (strlen(d) != 4){ }while(kontroll(d) == 1);
printf("Vale!"); printf("\n");
} printf("\nTerviklik kaart:\n");
for (i = 0; i < strlen(d); i++){
if (d[i] != '0' && d[i] != '1'){
printf("Lubamatu sisend: %s", d);
return 1;
}
}
printf("\n%s\n", a); printf("\n%s\n", a);
printf("%s\n", b); printf("%s\n", b);
printf("%s\n", c); printf("%s\n", c);
printf("%s\n", d); printf("%s\n", d);
printf("\n");
}
else if (strlen(a) >= 16){
for (i = 0; i < 16; i++){
if (a[i] != '0' && a[i] != '1'){
printf("\nLubamatu sisend: %s\n", a);
return 1;
}
}
printf("\n");
printf("Toevaartused: %s", a);
printf("\n");
}
else{ // Kui kasutaja sisestab mittesobiva märkide arvu, siis programm teeb exit.
printf("Lubamatu sisend: %s\n", a);
return 1;
} }
else if (strlen(a) == 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;
if (strlen(a) >= 16){
f0 = a[0];
f1 = a[1];
f2 = a[2];
f3 = a[3];
f4 = a[4];
f5 = a[5];
f6 = a[6];
f7 = a[7];
f8 = a[8];
f9 = a[9];
fA = a[10];
fB = a[11];
fC = a[12];
fD = a[13];
fE = a[14];
fF = a[15];
} }
else{ else{
printf("Lubamatu sisend: %s", a); f0 = a[0];
return 1; f1 = a[1];
f2 = a[3];
f3 = a[2];
f4 = b[0];
f5 = b[1];
f6 = b[3];
f7 = b[2];
f8 = c[0];
f9 = c[1];
fA = c[3];
fB = c[2];
fC = d[0];
fD = d[1];
fE = d[3];
fF = d[2];
}
if (f0 == '1'){
printf("Konstant 1 olemas.\n");
}
else{
printf("Konstant 1 puudub.\n");
}
if (fF == '1'){
printf("PAARITU arv liikmeid\n");
}
else{
printf("PAARISarv liikmeid\n");
}
if (f0 == f8){
printf("x1 puudub.\n");
}
else{
printf("x1 olemas\n");
}
if (f0 == f4){
printf("x2 puudub.\n");
}
else{
printf("x2 olemas\n");
}
if (f0 == f2){
printf("x3 puudub.\n");
}
else{
printf("x3 olemas\n");
}
if (f0 == f1){
printf("x4 puudub.\n");
} }
else{
printf("x4 olemas\n");
}
if (f7 == 1){
printf("ilma [x1] PAARITU.\n");
}
else{
printf("ilma [x1] PAARIS\n");
}
if (fB == 1){
printf("ilma [x2] PAARITU.\n");
}
else{
printf("ilma [x2] PAARIS\n");
}
if (fD == 1){
printf("ilma [x3] PAARITU.\n");
}
else{
printf("ilma [x3] PAARIS\n");
}
if (fE == 1){
printf("ilma [x4] PAARITU.\n");
}
else{
printf("ilma [x4] PAARIS\n");
}
}
int main(void){
char a[16], b[16], c[16], d[16];
sisestus("Sisestage 4x4 Karnaugh kaart voi 16 loogikavaartust: \n", a, b, c, d);
info(a, b, c, d);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment