The task is:
Input from file input.txt and output to file output.txt The first line is target number. The second line is sequence of positive integers in range
1to999999999.If any two of these integers in sum equals to the target the program has to output 1 otherwise 0.
Example:
5
1 7 3 4 7 9
Output: 1
There is my program. It pass 5 tests and fails the 6th - wrong result. I need help to find the bug or rewrite it.
#include <stdio.h>
int main() {
FILE *fs = fopen("input.txt", "r");
int target;
fscanf(fs, "%d", &target);
unsigned char bitset[1 + target / 8];
int isFound = 0;
for (int number; !isFound && fscanf(fs, "%d", &number) == 1;) {
if (number <= target) {
const int compliment = target - number;
isFound = (bitset[compliment / 8] & (1 << (compliment % 8))) > 0;
bitset[number / 8] |= 1 << (number % 8);
}
}
fclose(fs);
fs = fopen("output.txt", "w");
fprintf(fs,"%d", isFound);
fclose(fs);
return 0;
}