// 문제 1: 타이머 프로그램
#include <stdio.h>
#include <unistd.h> // sleep() 함수 사용을 위해 포함
int main() {
int seconds;
printf("초를 입력하세요: ");
scanf("%d", &seconds);
while (seconds > 0) {
printf("남은 시간: %d초\n", seconds);
sleep(1); // 1초 대기
seconds--;
}
printf("타이머 종료!\n");
return 0;
}
// 문제 2: 간단한 스톱워치
#include <stdio.h>
#include <time.h>
int main() {
char command;
time_t start, end;
double elapsed;
printf("스톱워치를 시작하려면 's'를, 종료하려면 'e'를 입력하세요.\n");
while (1) {
printf("명령 입력: ");
scanf(" %c", &command); // 공백을 추가하여 이전 버퍼 값을 무시함
if (command == 's') {
start = time(NULL);
printf("스톱워치 시작!\n");
} else if (command == 'e') {
end = time(NULL);
elapsed = difftime(end, start);
printf("경과 시간: %.2f초\n", elapsed);
break;
}
}
return 0;
}