Comparison of matrix and vector C/C++

Asked

Viewed 397 times

1

I need to compare a user-inserted op vector with the top 10 columns of each row of a 12x12 array.

for(k=0; k<10; k++){
for(i=0; i<12; i++){
    for(j=0; j<10; j++){
        if(op[k]==d[i][j]){
            if(i==1)
                flagd1++;
            if(i==2)
                flagd2++;
            if(i==3)
                flagd3++;
            if(i==4)
                flagd4++;
            if(i==5)
                flagd5++;
            if(i==6)
                flagd6++;
            if(i==7)
                flagd7++;
            if(i==8)
                flagd8++;
            if(i==9)
                flagd9++;
            if(i==10)
                flagd10++;
            if(i==11)
                flagd11++;
            if(i==12)
                flagd12++;
        }
    }
}

}

  • In your code you are comparing for each vector box the i (12) row matrix and j (10) column. The flags you are setting according to the line number, if the line is 1 the flagd1 will be incremented in 1. I don’t understand very well what you want, your code matches what you want. I saw only one mistake here: if(i==10) flagd11++;

  • what you want to do in this flag?

  • This pattern of several ifs in one for on the basis of i is always wrong. Imagine that they were not 10 houses but yes 100, was going to do 100 ifs ? The idea of using fors is precisely to be able to automate these kinds of things

  • @Forsaiken I’m making a score, it’s a code to identify the vector op informed by the user and compare it with a matrix already defined. " In your code you are comparing for each vector box the i (12) row matrix and j (10) column. The flags you are setting as the line number, if the line is at 1 the flagd1 will be incremented at 1.". That’s exactly what I wish.

  • @Isac, yes, but it is a 12x12 array and the last column will be used to store the flags and the penultimate will be enumerated from 1 to 12 for later idenfication. Have any suggestions to change the way I do it?

  • @Feliperezende Just seeing how the flags are used could give a hint of how to solve

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.