cpp/thread/promise
From cppreference.com
- include<iostream>
- include<cstdio>
- include<cmath>
using namespace std;
double function(double x, double y ) {
return sqrt(x * x + y * y);
} //double(*pt_fun)(double , double) = NULL; //pt_fun = &function;
void arr_fun(double *arr1, double *arr_result, int n ){
int k = 0; for( int i = 0; i < n ; i+=2){ arr_result[k] = function( arr1[i], arr1[i + 1] ); k++; }
}
int main(){
int n = 8;
double* arr1 = new double [n]; double arr2[] = {1.0 , 1.0 , 2.0, 1.0 , 1.0, 3.0, 3.0, 1.0};
for(int i = 0; i < n; i ++) arr1[i]=arr2[i];
double *a = new double [n / 2]; arr_fun(arr1,a, n ); for ( int i = 0; i < n / 2; i++){
cout << a[i] << " ";
} cout << endl;
//OUT: [1.414214 2.236068 3.162278 3.162278]
delete []a; delete []arr1; return 0;
}