More actions
No edit summary |
(Repair batch-0006 pages from live compare) |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 124: | Line 124: | ||
= 실습 = | = 실습 = | ||
* 실습 코드를 여기 작성해 주세요. | * 실습 코드를 여기 작성해 주세요. | ||
* 6번 추가됨 | |||
* 안재형 | * 안재형 | ||
| Line 246: | Line 247: | ||
*이민지 | |||
#1 | *#1 | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 267: | Line 268: | ||
} | } | ||
#2 | *#2 | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 286: | Line 287: | ||
} | } | ||
#3 | *#3 | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 308: | Line 309: | ||
#4 | *#4 | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 349: | Line 350: | ||
} | } | ||
#6 | *#6 | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 370: | Line 371: | ||
} | } | ||
| Line 441: | Line 442: | ||
break; | break; | ||
} | } | ||
} | |||
} | |||
6번 | |||
#include <stdio.h> | |||
main() | |||
{ | |||
int i, j, l, k; | |||
scanf_s("%d", &j); | |||
for (i = 1; i <= j; i++) | |||
{ | |||
for (l = 1; l <= i-1; l++) | |||
printf(" "); | |||
for (k = i; k <= j; k++) | |||
printf("*"); | |||
printf("\n"); | |||
} | } | ||
} | } | ||
| Line 450: | Line 466: | ||
~~잘썼다~~ | ~~잘썼다~~ | ||
Latest revision as of 01:08, 27 March 2026
예정
- 제어/반복문이니 오늘은 실습을 합니다.
- 강의 1시간/실습 1시간 예정입니다.
- 제어문
- 조건문
- if
- else
- if-else if
- else if는 사실...
- switch
- switch-break
- default
- 반복문
- while
- do - while;
- for
- 무한루프
- 기타 제어문
- break
- continue
- goto
------------1시간-------------
- 배열도 안배웠고 그냥 별이나 찍읍시다.
- 시간 되는대로 합니다. ~~남으면 어쩔 수 없지~~
- #1 : for문 실습
* ** *** **** ***** ****** ******* ******** ********* **********
- #2 : for문 계속
********** ********* ******** ******* ****** ***** **** *** ** *
- #3 : #1을 while문으로
- #4 : for문 + if문 실습
* @@ ### **** @@@@@ ###### ******* @@@@@@@@ ######### **********
- if이 아니어도 좋습니다.
- ~~#5 : #1을 goto문으로~~
- ~~내가 너무 똑똑해서 지능을 썩히기 아깝다면 해보세요.~~
진행
- 제어문
*조건문(if, switch) *반복문(while, do-while, for)
- if문
*if(조건) -> 참일때 여러개의 문장을 실행시켜라 *else if -> else 다음 if 가 나오는 거다.
- &&일때 앞이가 0이면 뒤에것 실행 안함, ||일때 앞이가 1이면 뒤에것 실행 안함.
*()안에 =을 넣어도 컴파일 오류 안뜸. 쓰면 ㄴㄴ ~~뭔가 더 해줄라고 했는데 생각이 안난데~~
- while문
*(조건)에 해당하는 경우에만 실행. *맨처음부터 조건이 0일시 실행되지 않음. *(1)무한 루프 걸림. *do~while()은 뒤에 조건 들어가서 무조건 1번 실행 *do ~ while(); while()에 세미콜론 꼭 쓰기!!!!
- for문
*for(초기;조건;증감) *초기안에 여러개 동시 사용 가능(i=0, j=0.....) 등등 다른 것들도 뭐 마찬가지 *증감문에서 2개씩 증가하고 싶다.(i+=2 사용!) ~~(i+2얘만 쓰면 안된다!)~~ *증감문 안에 printf 써도 됨. *어디부터 시작, 조건 항상 신중하게 생각 ~~안그러면 배열에서 터진다~~ *for문 무한루프 = for(;;) ~~while에서는 비우면 안된다!~~
*break *주로 if문에서 사용, 아니면 switch문에서 사용! *무한루프 만들어 놓고 조건 만족시 프로그램 종료시킬 때 주로 사용.
*continue *조건 만족시 제일 처음으로 되돌아 간다. *if문이랑 많이 쓴다. ~~근데 보통 많이 안쓴다고 한다.~~ *for문 내에서 if문과 결합시켜서 특정 조건을 건너뛰고 싶을 때 if문 안에서 사용가능하다!(if 안에 continue 쓴 부분은 패스하고 다시 앞으로 돌아가서 실행!)
*switch *switch()안에는 무조건 정수형(문자를 넣어도 실행되는 이유는 char이 결국 정수형이라서!) *해당하는 case가 없는 경우에는 default로 감. *break가 없을 경우 c가 1로 가면 1을 시행 후 그 뒤에 값을 전부 시행! (그래서 break 사용) *case 1뒤에는 콜론 사용 ':' ~~세미콜론이랑 다르니까 조심~~
*goto ~~왠만하면 쓰지 마세용~~ *'a_lable :' 이렇게 쓰고 뒤에 코드 작성 가능. *예시
- int main()
{
def:
goto abc;
abc:
goto def;
}
이런식으로 작성가능하다! 어느 위치에 있던지(위든 아래든) 이동 가능하다!!!!!!!
~~무한 반복, 생략의 오류 많이 생길 수 있으므로 되도록 사용 말것!!!~~
*~~goto를 쓰는 상황이면 뭔가 잘못된 상황이다. 되도록 쓰지 않도록!!!~~
*
실습
- 실습 코드를 여기 작성해 주세요.
- 6번 추가됨
- 안재형
- #1
- include <stdio.h>
int main() { int temp_a, temp_b;
for (temp_a=1 ; temp_a<=10 ; temp_a++) { for (temp_b = 1; temp_b <= temp_a; temp_b++) { printf("*"); } printf("\n"); }
return 0; }
- #2
- include <stdio.h>
int main() { int temp_a, temp_b;
for (temp_a=1 ; temp_a<=10 ; temp_a++) { for (temp_b = 10; temp_b >= temp_a; temp_b--) { printf("*"); } printf("\n"); }
return 0; }
- #3
- include <stdio.h>
int main() { int temp_a, temp_b;
temp_a = 1; while (temp_a <= 10) { temp_b = 1; while (temp_b <= temp_a) { temp_b++; printf("*"); } printf("\n"); temp_a++; }
return 0; }
- #4
- include <stdio.h>
int main() { int decide; int temp_a, temp_b;
for (temp_a = 1; temp_a <= 10; temp_a++) { for (temp_b = 1; temp_b <= temp_a; temp_b++) { switch (temp_a % 3) { case 0: printf("#"); break; case 1: printf("*"); break; case 2: printf("@"); break; } } printf("\n"); }
return 0; }
- ~~재능낭비 5번 패스~~
- #6
- include <stdio.h>
int main() { int temp_a, temp_b, temp_c;
for (temp_a = 1; temp_a <= 10; temp_a++) { for (temp_c = temp_a - 1 ; temp_c > 0; temp_c--) { printf(" "); } for (temp_b = 10; temp_b >= temp_a; temp_b--) { printf("*"); } printf("\n"); }
return 0; }
*이민지
*#1
- include <stdio.h>
int main() { int i, j; for (i = 1; i < 11; i++) { for (j = 0;j<i; j++) { printf("*"); } printf("\n");
} printf("\n"); return 0; }
*#2
- include <stdio.h>
int main() { int i, j; for (i = 1; i < 11; i++) { for (j = 11; j>i; j--) { printf("*"); } printf("\n");
} printf("\n"); return 0; }
*#3
- include <stdio.h>
int main() { int i=1, j; while (i < 11) { j = 0; while(i>j) { printf("*"); j++; } printf("\n"); i++; } printf("\n"); return 0; }
*#4
#include <stdio.h>
int main() { int n, i, j; printf("원하는 수를 입력하시오. : "); scanf_s("%d", &n);
for (i = 1; i <= n; i++) { if (i%3==1) { for (j = 0; j < i; j++) { printf("*"); } printf("\n"); } else if(i%3==2) { for (j = 0; j < i; j++) { printf("@"); } printf("\n"); } else if(i%3==0) { for (j = 0; j < i; j++) { printf("#"); } printf("\n"); }
} printf("\n"); return 0; }
*#6
- include <stdio.h>
int main() { int i=1, j; while (i < 11) { j = 0; while(i>j) { printf("*"); j++; } printf("\n"); i++; } printf("\n"); return 0; }
김경태
1번
- include <stdio.h>
main() { int a, b; for (a = 1; a <= 10; a++) { for (b = 1; b <= a; b++) printf("*"); printf("\n"); } } 2번
- include <stdio.h>
main() { int a, b; for (a = 1; a <=10; a++) { for(b=10; b>=a; b--) printf("*"); printf("\n"); } } 3번
- include <stdio.h>
main() { int i=1, j=1; while (i <= 10) { while (j <= i) { printf("*"); j++; } j = 1; i++; printf("\n"); } } 4번
- include <stdio.h>
main() { int n, a, i; scanf_s("%d", &n); for (a = 1; a <= n; a++) { switch (a % 3) { case 1: for (i = 1; i <= a; i++) printf("*"); printf("\n"); break; case 2: for (i = 1; i <= a; i++) printf("@"); printf("\n"); break; case 0: for (i = 1; i <= a; i++) printf("#"); printf("\n"); break; } } } 6번
- include <stdio.h>
main() { int i, j, l, k; scanf_s("%d", &j); for (i = 1; i <= j; i++) { for (l = 1; l <= i-1; l++) printf(" "); for (k = i; k <= j; k++) printf("*"); printf("\n"); } }
기타 / 후기 / 방명록
~~잘썼다~~