help preaty please

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
The two operations would be the same.

But anyway, this question was asked recently.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace 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;
}


Original was here: http://www.cplusplus.com/forum/beginner/68/
Converted from C to C++ (for the obvious reasons, such as the name of the website being cplusplus.com)
Topic archived. No new replies allowed.