Back to General discussions forum
This is my code:
#include <stdio.h>
int calculate_checksum(int length, int array[]) {
int result = 0;
int seed = 113;
int limit = 10000007;
for(int i = 0; i < length; i++) {
result = (result + array[i]) * seed;
result = result % limit;
}
return result;
};
int main() {
int x,i;
scanf("%d", &x);
int jawaban[x];
for(i=0;i<x;i++) {
scanf("%d", &jawaban[i]);
}
int proses = calculate_checksum(x,jawaban);
printf("%d ", proses);
return 0;
}
When i put the example, the code generates same answer.
But is not for test data.
Where are my code fault?
Hi, you store everything as int
.
Have a look whether your calculations could produce numbers greater than the max value for int
in C++, i.e.
whether you could get an overflow error.
okay thank you @gardengnome