NOTE: I had two variables with the same name... Big thanks to Stefan Birladeanu and Henrik for noticing that!*
Recently I started writing code that helps me input the values of bool function to Veitch (Karnaugh) diagram with 4 variables. The code should write elements to matrix size 4x4 but with these indexes:
- element - index 3,3
- element - index 2,3
- element - index 3,2
- element - index 2,2
- element - index 0,3
- element - index 1,3
- element - index 0,2
- element - index 1,2
- element - index 3,0
- element - index 2,0
- element - index 3,1
- element - index 2,1
- element - index 0,0
- element - index 1,0
- element - index 0,1
element - index 1,1 This is the code of main():
void main() { int n; n=4; int **VeitchDiagram; //allocate memory for Veitch diagram VeitchDiagram = new int *[n]; for(int i=0; i<n; i++) VeitchDiagram[i]=new int [n]; //enter the elements for(int i=0; i<n; i++) { int j, k; if(i%2==1) { k=0; if(i<2) j=4; else j=-1; for(int k=0; k<2; k++) { if(i<2) j--; else j++; cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that): k++; //0,3 1,3 0,2 1,2 if i%2==1 and i<2 cin >> VeitchDiagram[k][j]; //0,0 1,0 0,1 1,1 if i%2==1 and i>=2 k--; } } else { k=3; if(i<2) j=4; else j=-1; for(int k=0; k<2; k++) { if(i<2) j--; else j++; cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that): k--; //3,3 2,3 3,2 2,2 if i%2==0 and i<2 cin >> VeitchDiagram[k][j]; //3,0 2,0 3,1 2,1 if i%2==0 and i>=2 k++; } } } //free memory allocated for VeitchDiagram for(int i=0; i<n; i++) delete [] VeitchDiagram[i]; delete [] VeitchDiagram; }