我正在尝试创建一个4变量的kmap,但我不确定如何创建kmap的左侧(00->10)。谢谢你的帮助。:)
以下是我的代码
#include <stdio.h>
int main()
{
unsigned int w, x, y, z;
unsigned int f;
/* Print header for K-map. */
printf(" yz \n");
printf(" 00 01 11 10 \n");
printf(" ______________\n");
/* row-printing loop */
for (w = 0; 2 > w; w = w + 1)
{
for (x = 0; 2 > x; x++){
printf("w=%u%x | ", w,x);
}
/* Loop over input variable b in binary order. */
for (y = 0; 2 > y; y = y + 1)
{
/* Loop over d in binary order.*/
for (z = 0; 2 > z; z = z + 1)
{
/* Use variables b and d to calculate *
* input variable c (iterated in *
* Gray code order). */
/* CALCULATE c HERE. */
y = x^z;
/* Calculate and print one K-map entry *
* (function F(a,b,c) ). */
/* INSERT CODE HERE. */
f = (w|~x) & (~w|~y) & (w|~x|~y) & 1;
printf("%u ", f);
}
}
/* End of row reached: print a newline character. */
printf("\n");
}
return 0;
}对于进一步的信息,这是我必须做的“演示它的工作使用f(w,x,y,z) = xy'+w'z和g(w,x,y,z) =w‘’xyz‘+w+ x’作为例子”
发布于 2021-03-21 18:52:58
您有四个变量x、y、w和z,因此您需要一个带有4x4=16字段的kmap,就像https://www.geeksforgeeks.org/introduction-of-k-map-karnaugh-map/中的第二个示例一样。对于kmap中变量的位置及其负值,请将图片中的A、B、C、D替换为x、y、w、z:

字母到二进制数字的转换为
对所有术语进行简化,直到不能再简化更多的术语,此步骤中以下示例的输出为:
['10**', '1*0*', '1**0', '*110'],它与AB' + AC' + AD' + BCD'相同
来源:https://github.com/zhcHoward/Kmap
所以你基本上需要一个方阵
int matrix[4][4];
/*initialize matrix with '0'*/
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
matrix[i][j] = 0;
/* then needed fields to '1' i.e. xy', in most implementations the array is flattened for this */kmap求解器的源代码在http://krunalsiddhapathak.blogspot.com/2013/05/blog-post.html和中
对于验证步骤(“演示,...")参见此.cpp代码和背景(POS,quad,octant,...) ,和
https://stackoverflow.com/questions/66729971
复制相似问题