I need to write a program to calculate and print the result of the folowing two operations:
1/1+1/2+1/3+1/4+1/5+ ....=1/99999999+1/1000000000
and 1/1000000000+ 1/99999999 + 1/99999998+1/99999997+ .....+ 1/3+1/2+1/1
The results should be totaled once using float variables for each calculation and once using double variable for each cauculation . it may use (while do-while or for)
I cannot get nothing to work.
I am just learning and I dont even know how to start
#include <iostream>
usingnamespace std;
int main() {
double s = 0;
long n = 1000000;
for(long i = 1; i < n; i++)
s = s + (double) 1/i; // (double) cast the type of 1/i expression
cout << "s = " << s << endl;
return 0;
}