large_loop_array_1.sy 961 Bytes
Newer Older
龚平's avatar
init  
龚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//large loop and large array caculate
int COUNT = 500000;

float loop(float x[], float y[], int length) {
   int i = 0;
   float accumulator = 0.0;
   while (i < length) {
       accumulator = accumulator + x[i] * y[i];
       i = i + 1;       
   }
   return accumulator;
}

int main() {
    int i = 0, j = 0;
    int len = getint();
    float x[2048];
    float y[2048];
    float total = 0.0;
    float a = 0.0;
    float b = 1.0;
    starttime();
    while ( i < COUNT) {
        if (i % 10) {
            a = 0.0;
            b = 1.0;
        } else {
            a = a + 0.1;
            b = b + 0.2;
        }
	while ( j < len) {
	    x[j] = a + j;
            y[j] = b + j;
	    j = j + 1;
	}
	total = total + loop(x, y, len);
	i = i + 1;
    }
    stoptime();
    if ((total - 1430318598848512.000000) <=0.000001 || (total - 1430318598848512.000000) >= -0.000001) {
        putint(0);
	return 0;
    }
    else {
        putint(1);
	return 1;
    }

}