#include <stdio.h>
#include <stdbool.h>
#include <time.h>
bool is_leap_year(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {
FILE *file = fopen("leap_2000-2100_学号.txt", "w");
if (file == NULL) {
printf("Error opening file!\n");
return 1;
}
clock_t start = clock();
for (int year = 2000; year <= 2100; year++) {
if (is_leap_year(year)) {
fprintf(file, "%d\n", year);
}
}
clock_t end = clock();
fclose(file);
double time_spent = (double)(end - start) / CLOCKS_PER_SEC;
printf("Time spent: %f seconds\n", time_spent);
return 0;
}
gcc leap_years.c -o leap_years
./leap_years
#include <stdio.h>
#include <dirent.h>
int main() {
DIR *dir;
struct dirent *entry;
dir = opendir(".");
if (dir == NULL) {
perror("Unable to open directory.");
return 1;
}
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
return 0;
}
gcc lsc.c -o lsc
./lsc