-1
Well, I’ve been stuck on this show for a long time. I am inciante and the purpose of the question is to make operations between each element of two lists if the rest is 1, 2 and so on.
Example: 2 list with elements, 4 9 7
and 1 2 3
, you will add 4+1
if the division 4/4
is equal to zero.
#include <iostream>
using namespace std;
int main() {
int n, i, j, s =0, resto = 0;
cin >> n;
int vet[n], resultado[n];
for (i=0; i<n; i++){
cin >> vet[i];
}
for (j=0; j<n; j++){
cin >> vet[j];
}
for (i=0; i<n; i++){
resto = vet[i] % 4;
for (j=0; j<n; j++){
if (resto == 0){
resultado[i] = vet[i]+vet[j];
}
if (resto == 1){
resultado[i] = vet[i]-vet[j];
}
if (resto == 2){
resultado[i] = vet[i]*vet[j];
}
if (resto == 3){
resultado[i] = vet[i]/vet[j];
}
if (resto == 4){
resultado[i] = vet[i]^vet[j];
}
}
cout << resultado[i] << ' ';
}
}
When the division
4/4
is equal to zero? in the codeif (resto == 0){
why addvet[i]
withvet[j]
since the only way toresto
be equal to zero is ifvet[i]
for zero?– Augusto Vasques