C program for karnaugh map

Status
Not open for further replies.

siddharth_21

Honorable
Nov 5, 2012
1
0
10,510
please explain me this karnaugh map program


#include<stdio.h>
#include<conio.h>
void main()
{

int a[2000][10],b[2000][10],p[2000][10],q[2000][10],r[2000][10],s[2000][10],t[2000][10],u[2000][10],w[2000][10],o[2000][10],x[2000][10],y[6000][5],z[2000][10],c=1,c1=4,c2=1,c3=1,c4=1,c5=1,e=0,f=1,g=1,h=0,i,j,k,l=1,m,v;
clrscr();
printf("instruction");
printf("\nEnter 0 for not selecting and 1 for selecting\n");
for(i=0;i<=15;i++)
{
printf("value for cell %d=",i);
scanf("%d",&v);
if(v==1)
{
a[c][5]=i;
m=i;
while(c1!=0)

{
a[c][c1]=m%2;
m=m/2;
c1--;
}
c++;
c1=4;
}
}
for(i=1;i<c;i++)
{
for(j=1;j<c;j++)
{
for(k=1;k<=4;k++)
{
if(a[k]+a[j][k]==1) //a[11]+1[11],a[12][12],...a[23][23]//
e++; //e=1//
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(a[k]+a[j][k]!=1)
b[f][g]=a[k]; //b[11]=a[11]
else
b[f][g]=3; //b[11]=3//
g++; //g=1//
}
b[f][5]=a[5];
b[f][6]=a[j][5];
g=1;
f++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
x[c2][k]=a[k];
c2++;
}
h=0;
}
c=0;
for(i=1;i<f;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(b[k]==b[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=6;k++)
u[h+1][k]=b[k];
h++;
}
e=0;
}
for(i=1;i<=h;i++)
{
if(u[7]!=4)
{
for(j=1;j<=h;j++)
{
if(u[j][7]!=4)
{
if((u[6]==u[j][5])||(u[6]==u[j][5])||(u[5]==u[j][5])||(u[5]==u[j][6]))
{
for(k=1;k<=h;k++)
{
if(u[j][6]==u[k][5]||u[j][6]==u[k][6]||u[j][5]==u[k][5]||u[j][5]==u[k][6])
{
for(e=1;e<=h;e++)
{
if(i!=j&&i!=k&&i!=e&&j!=k&&j!=e&&k!=e)
{
if(u[k][6]!=u[e][5]&&u[k][6]!=u[e][6]&&u[k][6]!=u[e][6]&&u[k][6]!=u[e][5])
u[j][7]=4;
}
}
}
}
}
}
}
}
}
printf("\n");
f=h+1;
e=0;h=0;g=1;l=1;c=1;
for(i=1;i<f;i++)
{
for(j=1;j<f;j++)
{
for(k=1;k<=4;k++)
{
if(u[k]+u[j][k]==1)
e++;
if((u[k]+u[j][k]==3)||(u[k]+u[j][k]==4))
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(u[k]+u[j][k]!=1&&u[k]+u[j][k]!=6)
z[l][g]=u[k];
else
z[l][g]=3;
g++;
}
g=1;
l++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=7;k++)
w[c3][k]=u[k];
c3++;
}
h=0;
}
c=0;
for(i=1;i<l;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(z[k]==z[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
t[h+1][k]=z[k];
h++;
}
e=0;
}
l=h+1;
e=0;h=0;g=1;m=1;c=1;c1=4;
for(i=1;i<l;i++)
{
for(j=i+1;j<l;j++)
{
for(k=1;k<=4;k++)
{
if(t[k]+t[j][k]==1)
e++;
if(t[k]+t[j][k]==3||t[k]+t[j][k]==4)
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(t[k]+t[j][k]!=1&&t[k]+t[j][k]!=6)
y[m][g]=t[k];
else
y[m][g]=3;
g++;
}
g=1;
m++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
r[c4][k]=t[k];
c4++;
}
h=0;
}
c=0;h=0;
for(i=1;i<m;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(y[k]==y[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
s[h+1][k]=y[k];
h++;
}
e=0;
}
f=h+1;
e=0;h=0;g=1;l=1;c=1;
for(i=1;i<f;i++)
{
for(j=1;j<f;j++)
{
for(k=1;k<=4;k++)
{
if(s[k]+s[j][k]==1)
e++;
if((s[k]+s[j][k]==3)||(s[k]+s[j][k]==4))
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(s[k]+s[j][k]!=1&&s[k]+s[j][k]!=6)
q[l][g]=s[k];
else
q[l][g]=3;
g++;
}
g=1;
l++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
p[c5][k]=s[k];
c5++;
}
h=0;
}
c=0;
for(i=1;i<l;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(q[k]==q[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
o[h+1][k]=q[k];
h++;
}
e=0;
}
for(i=1;i<=h;i++)
{
printf("1");
}
printf("\n");
for(i=1;i<c2;i++)
{
if(x[1]==0)
printf("A'");
if(x[1]==1)
printf("A");
if(x[2]==0)
printf("B'");
if(x[2]==1)
printf("B");
if(x[3]==0)
printf("C'");
if(x[3]==1)
printf("C");
if(x[4]==0)
printf("D'");
if(x[4]==1)
printf("D");
printf("+");
}
c=0;
for(i=1;i<c3;i++)
{
if(w[7]!=4)
{
if(w[1]==0)
printf("A'");
if(w[1]==1)
printf("A");
if(w[2]==0)
printf("B'");
if(w[2]==1)
printf("B");
if(w[3]==0)
printf("C'");
if(w[3]==1)
printf("C");
if(w[4]==0)
printf("D'");
if(w[4]==1)
printf("D");
printf("+");
}
}
printf("\n");
c=0;
for(i=1;i<c4;i++)
{
for(j=1;j<=h;j++)
{
if(((o[j][1]-r[1])==2||(o[j][1]-r[1])==3||(o[j][1]-r[1])==0)&&((o[j][2]-r[2])==2||(o[j][2]-r[2])==3||(o[j][2]-r[2])==0)&&((o[j][3]-r[3])==2||(o[j][3]-r[3])==0||(o[j][3]-r[3])==3)&&((o[j][4]-r[4])==2||(o[j][4]-r[4])==0||(o[j][4]-r[4])==3))
c++;
}
for(j=1;j<c5;j++)
{
if(((p[j][1]-r[1])==2||(p[j][1]-r[1])==3||(p[j][1]-r[1])==0)&&((p[j][2]-r[2])==2||(p[j][2]-r[2])==3||(p[j][2]-r[2])==0)&&((p[j][3]-r[3])==2||(p[j][3]-r[3])==0||(p[j][3]-r[3])==3)&&((p[j][4]-r[4])==2||(p[j][4]-r[4])==0||(p[j][4]-r[4])==3))
c++;
}
if(c==0)
{
if(r[1]==0)
printf("A'");
if(r[1]==1)
printf("A");
if(r[2]==0)
printf("B'");
if(r[2]==1)
printf("B");
if(r[3]==0)
printf("C'");
if(r[3]==1)
printf("C");
if(r[4]==0)
printf("D'");
if(r[4]==1)
printf("D");
printf("+");
}
c=0;
}
printf("\n");
for(i=1;i<c5;i++)
{
if(p[1]==0)
printf("A'");
if(p[1]==1)
printf("A");
if(p[2]==0)
printf("B'");
if(p[2]==1)
printf("B");
if(p[3]==0)
printf("C'");
if(p[3]==1)
printf("C");
if(p[4]==0)
printf("D'");
if(p[4]==1)
printf("D");
printf("+");
}
getch ();
}

 

ex_bubblehead

Distinguished
Moderator
Ah, another homework assignment. You need to do better than simply posting code.

Is this your own work, or did you simply cut/paste from a book? (my bet is that it's a cut/paste job)
Does it compile?
Does it run?
What is the output supposed to look like?
What specifically do you want to know about this code?
 

randomizer

Distinguished


You have got to be kidding. That code is more unreadable than most minified JavaScript. If you got that from a textbook (although it looks worse than the rubbish in most textbooks too) please let me know which one so I can go and burn a few copies of it in protest.
 
Status
Not open for further replies.