MUstar

IoT C언어 0710 - EX13_2

Jul 15th, 2017
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void set(int h, int m);
  4. void show(void);
  5. void move(void);
  6.  
  7.  
  8. int hour,min,ck,now=1;
  9.  
  10. int main(void)
  11. {
  12.     int m_temp;
  13.     printf("최초 시간과 분 입력(24시간) : ");
  14.     scanf("%d%d",&hour,&min);
  15.     set(hour,min);
  16.     show();
  17.     printf("경과 시간 입력(분) : ");
  18.     scanf("%d",&m_temp);
  19.     now = 2;
  20.     for(int i=0; i<m_temp; i++) move();
  21.     if(hour==0&&ck==2)hour=12;
  22.     show();
  23.  
  24.     return 0;
  25.  
  26. }
  27.  
  28. void set(int h, int m)
  29. {
  30.     if(h<12)ck=1;
  31.     else
  32.     {
  33.         if(h==12) ck=2;
  34.         else hour=h-12; ck=2;
  35.     }
  36. }
  37.  
  38. void show(void)
  39. {
  40.     char ampm[3][5] = {"dummy","AM","PM"};
  41.     if(now==1)printf("설정된 시간 : %02d:%02d(%s)\n",hour,min,ampm[ck]);
  42.     else printf("현재 시간 : %02d:%02d(%s)\n",hour,min,ampm[ck]);
  43. }
  44.  
  45. void move(void)
  46. {
  47.     min++;
  48.     if(min==60)
  49.     {
  50.         hour++;
  51.         min=0;
  52.     }
  53.     if(hour>=12&&ck==1)
  54.     {
  55.         hour=hour-12;
  56.         ck=2;      
  57.     }
  58.     else if(hour>=12&&ck==2)
  59.     {
  60.         hour=hour-12;
  61.         ck=1;
  62.     }
  63. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×