Код: Выделить всё
int arr_1[1000];
double arr_2[1000];
// arr_1 and arr_2 to be assigned values.
// This step is neglected. Not important.
double val(int i){
int a = arr_1[i];
int b = arr_1[i+1];
if (a == b) {
return 0.0;
}
else {
// arr_1 is properly designed so not to worry about any kind of leakage.
return arr_2[a] * arr_2[b];
}
}
Код: Выделить всё
int main() {
double result = 0.0;
for (int k=0; k
Подробнее здесь: [url]https://stackoverflow.com/questions/78503962/efficient-vectorisation-of-cpp-functions-with-if-else-logic[/url]
Мобильная версия