How to calculate natural logarithm of the value of each elements in array with C++

1 Answer

0 votes
#include <bits/stdc++.h> 
   
int main() { 
    std::valarray<double> varr = { 2, 3, 5, 4, 7, 9 }; 
 
    varr = log(varr);  
   
    for (double &n : varr) { 
        std::cout << n << ", ";
    } 
}
   
    
    
    
/*
run:
    
0.693147, 1.09861, 1.60944, 1.38629, 1.94591, 2.19722, 
    
*/

 



answered Jun 14, 2020 by avibootz
...