I need help 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

I am just learning and I dont even know how to start
besides
# include <iostream>
using namespace std:
cout<<"1/1+1/2+1/3+1/4+1/5+ ....=1/99999999+1/1000000000">>

float =1/1...


Please help me ...
it takes at about 2 minutes with my centrino under winxp
but i think it does work ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream.h>
#include <conio.h>


void main() {
	double s = 0;
	double r = 0;
	unsigned long n = 1000000000;

	cout << "calculating sum and reverse sum"<< endl;
	cout << "please wait . . .\n"<< endl;

	for(unsigned long i = 1; i <= n; i++) {
		s = s + (double) 1/i;  // (double) cast the type of 1/i expression
	}

	for(unsigned long i = n; i >= 1; i--) {
		r = r + (double) 1/i;
	}

	cout << "sum     = " << s << endl;
	cout << "rev_sum = " << r << endl;
	getch();
}
Last edited on
Thanks Alex, it did not work but I delete .h and took of getch(); and worked however here the problem ..
The assgiment should be printed once using float variables for each calculation and I have to use one of (while ,do-while or for).
I am using visual c++ compiler.
I am so los,t please help!!!
Thank you,
Bianka
Topic archived. No new replies allowed.