Language/C
[따배씨] 5.7 나머지 연산 ~ 5.8 증가 ++, 감소 -- 연산자
migrationArc
2021. 5. 18. 16:25
따배씨 - 따라하며 배우는 C언어
5강 연산자, 표현식, 문장
5.7 나머지 연산 Modulus Operator
#include <stdio.h>
int main(){
int seconds = 0, minutes = 0, hours = 0;
printf("Input seconds: ");
scanf("%d", &seconds);
while (seconds >= 0){
minutes = seconds / 60;
seconds %= 60;
hours = minutes / 60;
minutes %= 60;
printf("%d hours, %d minutes, %d seconds\n", hours, minutes, seconds);
printf("Input seconds:");
scanf("%d", &seconds);
}
return 0;
}
- 나머지 연산 기호: ' % '
5.8 증가 ++, 감소 -- 연산자
#include <stdio.h>
int main(){
int a = 0;
a++; // a = a + 1 or a += 1;
printf("%d\n",a);
++a; // a = a + 1 or a += 1;
printf("%d\n", a);
double b = 0;
b++; // b = b + 1 or b += 1;
printf("%f\n",b);
++b; // b = b + 1 or b += 1;
printf("%f\n", b);
return 0;
}
- 전위 연산자
- ++a
- 연산이 먼저 수행 됨
- 후위 연산자
- a++
- 연산이 나중에 수행
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
실리콘 밸리의 프로그래머 : 네이버 블로그
안녕하세요! 홍정모 블로그에 오신 것을 환영합니다. 주로 프로그래밍 관련 메모 용도로 사용합니다. 강의 수강하시는 분들은 홍정모 연구소 카페로 오세요.
blog.naver.com
http://www.inflearn.com/course/following-c
홍정모의 따라하며 배우는 C언어 - 인프런 | 강의
'따배씨++'의 성원에 힘입어 새롭게 개발된 C 언어로 시작하는 프로그래밍 입문 강의입니다. '따배씨'와 함께 프로그래밍 인생을 업그레이드 해보세요., 따라하며 배우는 C언어 '따배씨++'의 성원
www.inflearn.com