I don't understand why my program doesn't work... Its supposed to find the sum of:
1*2 + 3*4 + 5*6 ... + 2003*2004
When i output what is being held in array[0] it gives me like 4.022+06 or something whereas it should be 1 and array[1] should be two
Code:
#include <iostream.h>
#include <math.h>
void main() {
int i, j;
double array[1002];
double sum=0;
double square;
for (j=0; j<1002; j++) {
for (i=1; i<=2004; i+=2) {
array[j]=i*(i+1);
}
}
for (i=0; i<1002; i++) {
sum+=array[i];
}
cout<<array[0]<<endl;
cout<<sum<<endl;
}