216k views
0 votes
A file is known to contain 500 integers and is named data and is a text document. Write a C program that counts how many numbers in the file that are multiples of 17. Arrays are not allowed. In your code also insert a comment as the final line, indicating the count of multiples of 17 given by the execution of your program.

User Raudi
by
9.0k points

1 Answer

4 votes

Final answer:

To count how many numbers in the file are multiples of 17, you can use a C program that reads each integer from the file and checks if it is divisible by 17.

Step-by-step explanation:

To count how many numbers in the file are multiples of 17, you can use a C program that reads each integer from the file and checks if it is divisible by 17. Here's an example:

#include <stdio.h>
int main() {
FILE *file;
int number, count = 0;
file = fopen("data.txt", "r");
if (file == NULL) {
printf("File not found!\\");
return 1;
}
while (fscanf(file, "%d", &number) != EOF) {
if (number % 17 == 0) {
count++;
}
}
fclose(file);
printf("Count: %d\\", count);
return 0;
}

This code reads integers from the file named "data.txt" and checks if each number is divisible by 17. It keeps a count of the multiples of 17 and finally prints the count. The count is the number of multiples of 17 in the file.

User Aydow
by
7.8k points