Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(void)
- {
- double light_speed = 300000;
- double distance = 149600000;
- double time;
- time = distance/light_speed;
- printf("빛의 속도는 %fkm/s\n", light_speed);
- printf("태양과 지구와의 거리 %fkm\n", distance);
- double min1 = time / 60; //소수점 포함한 분단위 계산
- int min = time / 60; //소수점 무시하는 분단위 계산
- double min2 = min1 - min; //분 단위로 나눴을때 소수점 아래 분리하기
- int sec = min2 * 60; //소수점 아래를 초단위로 변환
- if (sec + 0.5 < min2 * 60) ++sec; //sec 변수 + 0.5가 min2 * 60(소수단위 초) 보다 작으면 반올림한다.
- printf("도달 시간은 %d분 %d초\n", min, sec);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement