1. 연산자
산술 연산자
- 사칙 연산이 기본
- +, -, /, *, %
대입연산자
- = , += , -= , *= , /= , %=
증감 연산자
- a++, ++a, a--, --a
#include <stdio.h>
int main() {
int a=5;
printf("%d ",++a);
printf("%d ",a++);
printf("%d ",a);
return 0;
}
=> 출력 : 6 6 7
관계 연산자
- ==, !=, > , <, >= , <=
논리 연산자
- 두개의 조건식 등을 결합하여 하나의 결과값을 만들어낸다.
- ! , && , ||
int main() {
int a=5;
printf("%d", !a);
return 0;
}
=> 출력: 0
예제 문제- 합 구하기(연산자와 입출력)
#include <stdio.h>
int main() {
int a,b,c;
scanf("%d %d %d", &a, &b, &c);
printf("%d",a+b+c);
return 0;
}
2. 조건문
- 관계연산자로 분기
예제 문제 - 내림차순으로 정렬
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a < b) {
int temp = a;
a = b;
b = temp;
}
if (a < c) {
int temp = a;
a = c;
c = temp;
}
if (b < c) {
int temp = b;
b = c;
c = temp;
}
printf("내림차순 정렬: %d, %d, %d\n", a, b, c);
return 0;
}
'타입스크립트로 함께하는 웹 풀 사이클 개발(React, Node.js) > TIL' 카테고리의 다른 글
데브코스 11주차 Day4 - 함수포인터, 구조체/공용체/열거형, 동적 메모리 (0) | 2024.01.28 |
---|---|
데브코스 11주차 Day 3 - 변수와 메모리 생명주기, 배열과 포인터 with C (0) | 2024.01.27 |
데브코스 11주차 Day1 - 컴파일, 변수와 메모리영역 with C (3) | 2024.01.25 |
데브코스 10주차 Day 1,2 - 페어코드, 마무리, 랜덤데이터 생성 api (0) | 2024.01.23 |
데브코스 9주차 Day 5 - jwt, 예외처리 with) throw-catch (0) | 2024.01.13 |