Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <math.h>
- #include <vector>
- #include <algorithm>
- #define LIMITPOWER 8
- using namespace std;
- // Auxiliary Functions
- double sumHarmonic(int a, int b){
- if(a > b){
- return -1000;
- }
- double sum = 0.0;
- for(int i=a; i<b+1; i++){
- sum += double(1) / double(i);
- }
- return sum;
- }
- double ln(int n){
- return log(n);
- }
- double calculateEulerConstant(int n){
- return sumHarmonic(1, n) - ln(n);
- }
- int main()
- {
- vector <double> sums = vector <double> ();
- vector <double> logarithms = vector <double> ();
- vector <double> euler = vector <double> ();
- for(int i=0; i<LIMITPOWER; i++){
- sums.push_back(sumHarmonic(1, pow(10, i+1)));
- logarithms.push_back(ln(pow(10, i+1)));
- euler.push_back(calculateEulerConstant(pow(10, i+1)));
- }
- for(int i=0; i<LIMITPOWER; i++){
- cout << "~~~~~~~~ Range 1 - " << pow(10,i+1) << " ~~~~~~~~" << endl;
- cout << " 1 + 1/2 + 1/3 + .... + 1/" << pow(10, i+1) - 1 << " + 1/" << pow(10, i+1) << " = " << sums[i] << endl;
- cout << "ln(" << pow(10, i+1) << ") = " << logarithms[i] << endl;
- cout << "Euler constant = " << euler[i] << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement