Advertisement
Albert3069

4 weeks project - 202007032 최윤솔

May 3rd, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void)
  5. {
  6.  
  7.     double light_speed = 300000;
  8.     double distance = 149600000;
  9.     double time;
  10.    
  11.     time = distance/light_speed;
  12.    
  13.     printf("빛의 속도는 %fkm/s\n", light_speed);
  14.     printf("태양과 지구와의 거리 %fkm\n", distance);
  15.    
  16.     double min1 = time / 60; //소수점 포함한 분단위 계산
  17.     int min = time / 60; //소수점 무시하는 분단위 계산
  18.     double min2 = min1 - min; //분 단위로 나눴을때 소수점 아래 분리하기
  19.     int sec = min2 * 60; //소수점 아래를 초단위로 변환
  20.    
  21.     if (sec + 0.5 < min2 * 60) ++sec; //sec 변수 + 0.5가 min2 * 60(소수단위 초) 보다 작으면 반올림한다.
  22.    
  23.     printf("도달 시간은 %d분 %d초\n", min, sec);
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement