#include #include int main() { FILE *fp; int numbers[100], read_numbers[100]; int i; // Initialize array with values 1 to 100 for (i = 0; i < 100; i++) { numbers[i] = i + 1; } // --- Writing to file using fwrite --- fp = fopen("numbers.bin", "wb"); if (fp == NULL) { perror("Error opening file for writing"); return 1; } size_t written = fwrite(numbers, sizeof(int), 100, fp); if (written != 100) { perror("Error writing to file"); fclose(fp); return 1; } fclose(fp); printf("Successfully wrote 100 integers to file.\n"); // --- Reading back using fread --- fp = fopen("numbers.bin", "rb"); if (fp == NULL) { perror("Error opening file for reading"); return 1; } size_t read = fread(read_numbers, sizeof(int), 100, fp); if (read != 100) { perror("Error reading from file"); fclose(fp); return 1; } fclose(fp); printf("Successfully read %zu integers from file.\n", read); // --- Display first 10 numbers for verification --- printf("First 10 integers read from file:\n"); for (i = 0; i < 10; i++) { printf("%d ", read_numbers[i]); } printf("\n"); return 0; }