1. "Hello, World!" 출력: 가장 기초적인 프로그램입니다. 콘솔창에 "Hello, World!"를 출력합니다
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
2. 사용자 입력: 키보드로부터 사용자 입력을 받아 처리하는 예제입니다.
#include <stdio.h>
int main() {
int age;
printf("What is your age? ");
scanf("%d", &age);
printf("Your age is: %d\n", age);
return 0;
}
3. 반복문: for, while, do-while 반복문을 사용하는 예제입니다.
#include <stdio.h>
int main() {
int i;
printf("for loop:\n");
for (i = 0; i < 10; i++) {
printf("%d ", i);
}
printf("\nwhile loop:\n");
i = 0;
while (i < 10) {
printf("%d ", i);
i++;
}
printf("\ndo-while loop:\n");
i = 0;
do {
printf("%d ", i);
i++;
} while (i < 10);
return 0;
}
4. 조건문: if, if-else, switch-case를 사용하는 예제입니다.
#include <stdio.h>
int main() {
int a = 10, b = 20;
if (a < b) {
printf("a is less than b\n");
}
if (a == b) {
printf("a is equal to b\n");
} else {
printf("a is not equal to b\n");
}
int x = 3;
switch (x) {
case 1:
printf("x is 1\

'차리토 실험실' 카테고리의 다른 글
| C언어 예제 #3 (변수와 데이터 타입) (0) | 2023.03.31 |
|---|---|
| C언어 예제 #2 (배열, 함수, 구조체, 파일 입출력) (0) | 2023.01.20 |
| C언어 Timer 기능(코드, time.h) (0) | 2023.01.20 |
| 분산계산 C코드 (0) | 2023.01.19 |
| [Routinize yourself] Look back your impression as a routiner during last year (0) | 2022.12.24 |