Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Outlier
- 데이터프레임
- 누락값
- 파이썬
- subplots
- MSE
- 대치법
- sklearn
- BDA
- matplotlib
- 선형보간
- 전처리
- 보간법
- SimpleImputer
- IterativeImputer
- Boxplot
- value_counts
- koNLPy
- join
- Python
- 불용어
- 결측치대체
- stopwords
- KoNLP
- 결측치
- interpolate
- Seaborn
- 이상치
- countplot
- DataFrame
Archives
- Today
- Total
ACAIT
[C] C언어 for Beginner 4판 응용 문제, 결과 추측하기 본문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <time.h> #include <string.h> char* upper_lower(char* s) { int i; int diff = 'a' - 'A'; for (i = 0; i < strlen(s); i++) { if (s[i] >= 'A' && s[i] <= 'Z') s[i] += diff; else if (*(s + i) >= 'a' && *(s + i) <= 'z') *(s + i) -= diff; } return s; } int getLotto() { return rand() % 45 + 1; } char* upper_lower_re(char* s) { int i; int diff = 'a' - 'A'; for (i = 0; i < strlen(s); i++) { if (*(s + i) >= 'A' && *(s + i) <= 'Z') *(s + i) += diff; else if (s[i] >= 'a' && s[i] <= 'z') s[i] -= diff; } return s; } int throwDice() { return rand() % 6 + 1; } void main() { // C언어 for beginner 4판 연습문제 기본 + 응용 풀이 // 08-예제모음22) int i, k; int gugu[8][9]; for (i = 2; i < 10; i++) { printf("#제%d단# ", i); } printf("\n"); for (i = 0; i < 9; i++) { for (k = 0; k < 8; k++) { gugu[k][i] = (i + 1) * (k + 2); printf("%dX%d= %2d ", k + 2, i + 1, gugu[k][i]); } printf("\n"); } printf("\n"); // 08-예제모음22) int i, k; int gugu[8][9]; FILE* wfp; wfp = fopen("c:\\cookc\\gugu0618.txt", "w"); for (i = 2; i < 10; i++) { printf("#제%d단# ", i); fprintf(wfp, "#제%d단# ", i); } printf("\n"); fprintf(wfp, "\n"); for (i = 0; i < 9; i++) { for (k = 0; k < 8; k++) { gugu[k][i] = (k + 2) * (i + 1); printf("%dX%d= %2d ", k + 2, i + 1, gugu[k][i]); fprintf(wfp, "%dX%d= %2d ", k + 2, i + 1, gugu[k][i]); } printf("\n"); fprintf(wfp, "\n"); } printf("\n"); fprintf(wfp, "\n"); fclose(wfp); // 08-09) int i, size; char imsi[100]; char* p; char old, new; printf("문자열: "); gets(imsi); printf("문자들: "); scanf(" %c %c", &old, &new); size = strlen(imsi); p = (char*)malloc((sizeof(char) * size) + 1); strcpy(p, imsi); printf("변환: "); for (i = size - 1; i >= 0 ; i--) { if (p[i] == old) *(p + i) = new; printf("%c", p[i]); } printf("\n"); // 08-09) int i, size; char imsi[100]; char* p; char old, new; printf("기존 문자열: "); gets(imsi); size = strlen(imsi); p = (char*)malloc((sizeof(char) * size) + 1); strcpy(p, imsi); printf("문자들: "); scanf(" %c %c", &old, &new); for (i = 0 ; i < size ; i++) { if (*(p + i) == old) { *(p + i) = new; } } upper_lower(p); printf("변환 문자열: "); for (i = size - 1; i >= 0; i--) { printf("%c", p[i]); } printf("\n"); free(p); // 09-응용9-2) char car = 'A'; int top = 0; char stack[5]; int answer; do { printf("<1> push, <2> pop, <3> stop: "); scanf("%d", &answer); switch (answer) { case 1: if (top < 5) { stack[top] = car; printf("%c차 push \n", stack[top]); top++; car++; } else printf("push 불가 \n"); break; case 2: if (top > 0) { top--; car--; printf("%c차 pop \n", stack[top]); stack[top] = ' '; } else printf("pop 불가 \n"); break; case 3: printf("현재 남은 차는 %d대 입니다. \n", top); break; default: printf("잘못 입력했습니다. \n"); break; } } while (answer != 3); // 09-08) char ary[25] = "ITCookBook $%& 1234"; char* p; int i; p = ary; int diff = 'a' - 'A'; for (i = sizeof(ary) - 2; i >= 0; i--) { if (p[i] >= 'a' && p[i] <= 'z') p[i] -= diff; else if (*(p + i) >= 'A' && *(p + i) <= 'Z') *(p + i) += diff; printf("%c", *(p + i)); } printf("\n"); // 09-09) int i, k, tmp; char s[100]; char* p; printf("입력: "); gets(s); p = s; printf("결과: "); for (i = 0; i < strlen(s); i++) { for (k = i + 1; k < strlen(s); k++) { if (*(p + i) < *(p + k)) { tmp = *(p + i); *(p + i) = *(p + k); *(p + k) = tmp; } } printf("%c", *(p + i)); } printf("\n"); // 09-09) int i, k, tmp; char s[100]; char* p; printf("기존: "); gets(s); p = s; printf("결과: "); for (i = 0; i < strlen(s); i++) { for (k = i + 1; k < strlen(s); k++) { if (p[i] > p[k]) { tmp = p[i]; p[i] = p[k]; p[k] = tmp; } } printf("%c", p[i]); } printf("\n"); // 10-예제29) int i, k, num; char dup = 'N'; int lotto[6] = { 0, }; i = 0; srand((unsigned)time(NULL)); while (1) { num = getLotto(); for (k = 0; k < 6; k++) if (lotto[k] == num) dup = 'Y'; if (dup == 'N') lotto[i++] = num; else dup = 'N'; if (i == 6) break; } for (i = 0; i < 6; i++) { printf("%d ", lotto[i]); } printf("\n"); // 10-08) char in[100], out[100]; printf("문자열: "); gets(in); strcpy(out, upper_lower_re(in)); printf("변환 결과 => %s \n", out); // 10-09) int diceNum[10] = { 0, }; int dice1, dice2; int equalCount = 0; int i; char dup = 'N'; srand((unsigned)time(NULL)); while (1) { dice1 = throwDice(); dice2 = throwDice(); if (equalCount == 10) break; if (dice1 == dice2) dup = 'Y'; else dup = 'N'; if (dup = 'Y') { diceNum[equalCount] = dice1; equalCount++; } } printf("같은 숫자 => "); for (i = 0; i < 10; i++) { printf("%d ", diceNum[i]); } printf("\n"); // 10-09) int diceNum[10] = { 0, }; int i; char dup = 'N'; int* p = diceNum; srand((unsigned)time(NULL)); int dice1, dice2; for (i = 0; i < 10;) { dice1 = throwDice(); dice2 = throwDice(); if (dice1 == dice2) dup = 'Y'; else dup = 'N'; if (dup = 'Y') { p[i] = dice1; i++; } } printf("같은 숫자 => "); for (i = 0; i < 10; i++) { printf("%d ", p[i]); } printf("\n"); // 11-예제30) int i, k; int gugu[8][9]; FILE* wfp; wfp = fopen("c:\\cookc\\gugu0618.txt", "w"); for (i = 2; i < 10; i++) { printf("#제%d단# ", i); fprintf(wfp, "#제%d단# ", i); } printf("\n"); fprintf(wfp, "\n"); for (i = 0; i < 9; i++) { for (k = 0; k < 8; k++) { gugu[k][i] = (k + 2) * (i + 1); printf("%dX%d= %2d ", k + 2, i + 1, gugu[k][i]); fprintf(wfp, "%dX%d= %2d ", k + 2, i + 1, gugu[k][i]); } printf("\n"); fprintf(wfp, "\n"); } printf("\n"); fprintf(wfp, "\n"); fclose(wfp); // 11-07) int i = 0; char s[100]; FILE* rfp; rfp = fopen("c:\\windows\\win.ini", "r"); while (1) { fgets(s, 100, rfp); if (feof(rfp))break; printf("%d : %s", i + 1, s); i++; } printf("\n"); fclose(rfp); // 11-07) int size; char imsi[100]; char* p; FILE* rfp; rfp = fopen("c:\\windows\\win.ini", "r"); int i = 0; while (1) { fgets(imsi, 100, rfp); size = strlen(imsi); if (feof(rfp)) break; p = (char*)malloc((sizeof(char) * size) + 1); strcpy(p, imsi); printf("%d : %s", i + 1, p); i++; } printf("\n"); fclose(rfp); free(p); // 11-08) int num, i; FILE* wfp; wfp = fopen("c:\\cookc\\rand0618.txt", "w"); srand((unsigned)time(NULL)); for (i = 0; i < 5; i++) { num = rand() % 100 + 1; printf("추출 숫자 => %d \n", num); fprintf(wfp, "추출 숫자 => %d \n", num); } printf("\n"); fprintf(wfp, "\n"); fclose(wfp); // 12-04) int* p; int i = 0; int hap = 0; int num; printf("랜덤 숫자 => "); srand((unsigned)time(NULL)); num = rand() % 100 + 1; p = (int*)malloc(sizeof(int) * 1); p[i] = num; printf("%d ", p[i]); hap = hap + p[i]; i = 2; while (1) { num = rand() % 100 + 1; p = (int*)realloc(p, sizeof(int) * i); p[i - 1] = num; if (p[i - 1] == 99 && i > 2) break; printf("%d ", p[i - 1]); hap = hap + p[i - 1]; i++; } printf("\n랜덤 합계 => %d \n", hap); free(p); // 12-04) int* p; int i = 0; int num; int hap = 0; FILE* wfp; wfp = fopen("c:\\cookc\\randhap0618.txt", "w"); srand((unsigned)time(NULL)); printf("랜덤 숫자 => "); fprintf(wfp, "랜덤 숫자 => "); p = (int*)malloc(sizeof(int) * 1); num = rand() % 100 + 1; p[i] = num; printf("%d ", p[i]); fprintf(wfp, "%d ", p[i]); hap = hap + p[i]; i = 2; while (1) { p = (int*)realloc(p, sizeof(int) * i); num = rand() % 100 + 1; p[i - 1] = num; if (p[i - 1] == 99 && i > 2) break; printf("%d ", p[i - 1]); fprintf(wfp, "%d ", p[i - 1]); hap = hap + p[i - 1]; i++; } printf("\n"); fprintf(wfp, "\n"); printf("랜덤 합계 => %d \n", hap); fprintf(wfp, "랜덤 합계 => %d \n", hap); fclose(wfp); free(p); // 12-07) int i, size; char* p[5]; char imsi[100]; FILE* rfp; rfp = fopen("c:\\windows\\win.ini", "r"); for (i = 0; i < 5; i++) { fgets(imsi, 100, rfp); size = strlen(imsi); p[i] = (char*)malloc((sizeof(char) * size) + 1); strcpy(p[i], imsi); printf("%d : %s", i + 1, p[i]); } for (i = 4; i >= 0; i--) { printf("%d : %s", i + 1, p[i]); } fclose(rfp); for (i = 0; i < 5; i++) { free(p[i]); } // 13-예제34) struct student { char name[10]; int age; }; struct student s; struct student* p; p = &s; int i, cnt; printf("입력할 학생 수: "); scanf("%d", &cnt); p = (struct student*)malloc(sizeof(struct student) * cnt); for (i = 0; i < cnt; i++) { printf("이름과 나이 입력: "); scanf("%s %d", p[i].name, &p[i].age); } printf("\n-- 학생 명단 --\n"); for (i = 0; i < cnt; i++) { printf("이름: %s, 나이: %d \n", p[i].name, p[i].age); } free(p); // 13-예제34) int i, cnt; struct student { char name[10]; int age; }; struct student s; struct student* p; p = &s; printf("입력 학생 수: "); scanf("%d", &cnt); p = (struct student*)malloc(sizeof(struct student) * cnt); for (i = 0; i < cnt; i++) { printf("이름, 나이: "); scanf("%s %d", p[i].name, &p[i].age); } printf("\n- 학생 명단 --\n"); for (i = 0; i < cnt; i++) { printf("이름: %s, 나이: %d \n", p[i].name, p[i].age); } free(p); // 13-예제36) enum month { Jan = 1, Fab, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }; enum month mm; printf("확인하고 싶은 달은? "); scanf("%d", &mm); // 열거형 변수에 값 대입 switch (mm) { case Jan: printf("%d월은 Jan. \n", mm); break; case Fab: printf("%d월은 Fab. \n", mm); break; case Mar: printf("%d월은 Mar. \n", mm); break; case Apr: printf("%d월은 Apr. \n", mm); break; case May: printf("%d월은 May. \n", mm); break; case Jun: printf("%d월은 Jun. \n", mm); break; case Jul: printf("%d월은 Jul. \n", mm); break; case Aug: printf("%d월은 Aug. \n", mm); break; case Sep: printf("%d월은 Sep. \n", mm); break; case Oct: printf("%d월은 Oct. \n", mm); break; case Nov: printf("%d월은 Nov. \n", mm); break; case Dec: printf("%d월은 Dec. \n", mm); break; default: printf("잘못 입력. \n"); break; } // 13-09) enum season{spring, summer, fall, winter}; enum season ss; ss = summer; if (ss = summer) printf("지금은 여름.\n"); else printf("여름은 아님.\n"); // 13-10) typedef struct _employee { union nm { char name[10]; char dept[10]; }; union nm nm; union id { char jumin[20]; char phone[13]; }; union id id; } employee; employee e1; printf("이름 또는 부서 => "); scanf("%s", e1.nm.name); printf("주소 또는 번호 => "); scanf("%s", e1.id.jumin); printf("\n-- 직원 명단 --\n"); printf("이름/부서: %s\n", e1.nm.dept); printf("주소/번호: %s\n", e1.id.phone); // 13-11) struct student { char name[10]; int avg; }; struct student s; struct student* p; p = &s; printf("이름: "); scanf("%s", p->name); printf("점수: "); scanf("%d", &p->avg); printf("\n-- 성적표 --\n"); printf("이름: %s, 점수: %d \n", p->name, p->avg); // 13-11) typedef struct _student_re { char name[10]; int avg; } student_re; student_re sr; student_re* pr; pr = &sr; int i, cnt; printf("학생 수: "); scanf("%d", &cnt); pr = (struct _student_re*)malloc(sizeof(struct _student_re) * cnt); printf("\n-- 정보 입력 --\n"); for (i = 0; i < cnt; i++) { printf("이름, 점수: "); scanf("%s %d", pr[i].name, &pr[i].avg); } printf("\n-- 성적 출력 --\n"); for (i = 0; i < cnt; i++) { printf("이름: %s, 점수: %d \n", pr[i].name, pr[i].avg); } free(pr); } | cs |
'전공 및 코드 > C프로그래밍' 카테고리의 다른 글
[C] 테트리스 코드 구현 및 분석 (0) | 2023.06.26 |
---|---|
[C] C언어 for Beginner 4판 예제, 연습문제, 응용 풀이 (1) | 2023.06.19 |
[C] C언어 for Beginner 4판 연습문제 응용 풀이 (1) | 2023.06.18 |
[C] C언어 for Beginner, 쉽게 풀어쓴 C언어 EXPRESS 연습문제 (0) | 2023.06.18 |
[C] C언어 for Bigenner 연습문제 응용 및 재풀이 (0) | 2023.06.18 |