본문 바로가기

분류 전체보기

(23)
C언어 콘서트 챕터6 프로그래밍 (~16번) 1. 간단한 카운트 다운 프로그램. #define _CRT_SECURE_NO_WARNINGS #include #include //rand(), srand() #include //time() int main(void) { for (int count = 60; count >= 0; count--) printf("%d ", count); printf("발사"); return 0; } 2. "안녕하세요" 입력받은 반복횟수만큼 출력 #define _CRT_SECURE_NO_WARNINGS #include #include //rand(), srand() #include //time() int main(void) { int repeat; printf("몇번이나 반복할까요? : "); scanf("%d", &repea..
C언어 콘서트 6장 미니 프로젝트 246P NIM게임 #define _CRT_SECURE_NO_WARNINGS #include #include //rand(), srand() #include //time() int main(void) { int input, cpt, each = 12; srand(time(NULL)); printf("현재 스틱의 개수 : %d \n", each); while ( 1 ) { printf("몇개의 스틱을 가져가시겠습니까? : "); scanf("%d", &input); if (input 3) {// 내가 음수 or 3을 초과하는 숫자를 입력했을 경우 실행 do { printf("\n===== 잘못된 숫자를 입력하셨습니다."); printf("\n==== = 0 ~3까지의 숫자로 다시 입력해주십시오.\n..
C언어 콘서트 6장 도전 문제 241P,242P 산수 문제 자동 출제 #define _CRT_SECURE_NO_WARNINGS #include #include //rand(), srand() #include //time() int main(void) { int ans, check = 0;// ans는 내가 입력할 답, check는 문제 맞춘 횟수 char a; // 부호를 담을 변수 srand(time(NULL)); printf("산수 문제를 자동으로 출제합니다.\n"); while (1) { int x = rand() % 100; int y = rand() % 100; int z = rand() % 4; if (z == 0) a = '+'; if (z == 1) a = '-'; if (z == 2) a = 'x'; if (z == 3) a = '/'; printf("%d..
C언어 콘서트 챕터6 218P 도전문제 int main(void) { int hour, min, sec, timer, i; hour = min = sec = i = 0; printf("타이머 설정(분): "); scanf("%d", &timer); while ( i
C언어 콘서트 챕터5 프로그래밍 201P 1. 사용자로부터 정수를 받아서 홀수인지 짝수인지 출력하는 프로그램을 작성하라. int main(void) { int num; printf("정수를 입력하시오: "); scanf("%d", &num); if (num % 2 == 0) printf("%d 은 짝수 입니다.", num); else printf("%d 은 홀수 입니다.", num); return 0; } 2. 사용자로부터 입력받은 두수의 합과 차를 구하여 출력하여 보자. 두수의 차는 큰 수에서 작은 수를 뺀 것으로 한다. int main(void) { int num1, num2; printf("정수를 입력하시오: "); scanf("%d", &num1); printf("정수를 입력하시오: "); scanf("%d", &num2); printf..
C언어 콘서트 챕터5 조건문 P196 이차방정식의 근 계산 int main(void) { int a, b, c; double d, e, f; printf("계수 a,b,c를 입력하시오: "); scanf("%d %d %d", &a, &b, &c); d = b * b - 4.0 * a * c; if (d == 0) { e = -b / (-2.0 * a); printf("같은 두 실근 = %f\n", e); } else if (d > 0) { e = (-b + sqrt(d)) / (2.0 * a); f = (-b - sqrt(d)) / (2.0 * a); printf("첫 번째 실근 = %f \n", e); printf("두 번째 실근 = %f \n", f); } else { printf("실근이 존재하지 않습니다.(허수근)"); } return 0; }
C언어 콘서트 챕터5 조건문 P193 도전문제 int main(void) { int year, month, days, yesorno; printf("윤년 여부를 알고싶은 연도와 일수를 알고싶은 달을 입력하시오 : "); scanf("%d %d", &year, &month); if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){ printf("%d년은 윤년입니다. \n", year); yesorno = 1; } else{ printf("%d년은 윤년이 아닙니다. \n", year); yesorno = 0; } switch (month){ case 2: if (yesorno == 1) days = 29; else days = 28; break; case 4: case 6: case 9: case 11: ..