digital clock program code


SUBMITTED BY: sunil

DATE: Dec. 7, 2015, 7:44 a.m.

FORMAT: Text only

SIZE: 3.0 kB

HITS: 333

  1. /*
  2. Name: sunil kumar
  3. Email ID: sunilcodex@gmail.com
  4. */
  5. #include<stdio.h>
  6. #include<conio.h>
  7. #include<string.h>
  8. void hour12();
  9. void hour24();
  10. int main()
  11. {
  12. system("color 5E");
  13. system("title Clock");
  14. int t,g;
  15. printf("enter 1 (12 hour) / 2 (24 hour)\n");
  16. scanf("%d",&t);
  17. switch(t)
  18. {
  19. case 1:
  20. system("cls");
  21. hour12();
  22. // break;
  23. case 2:
  24. system("cls");
  25. hour24();
  26. break;
  27. default:
  28. printf("default %d not errar\n",t);
  29. }
  30. getch();
  31. return 0;
  32. }
  33. void hour12()
  34. {
  35. long i;
  36. int sec=0,min=0,hour=0,t,g;
  37. char ch[4],am[]="AM",pm[]="PM";
  38. printf("enter hour\n");
  39. scanf("%d",&hour);
  40. if(13<hour)
  41. hour=1;
  42. printf("enter min\n");
  43. g=hour;
  44. scanf("%d",&min);
  45. if(61<min)
  46. min=0;
  47. printf("enter sec\n");
  48. scanf("%d",&sec);
  49. if(61<sec)
  50. sec=0;
  51. aaa:
  52. printf("enter 1 AM / 2 PM\n");
  53. scanf("%d",&t);
  54. switch(t)
  55. {
  56. case 1:
  57. strcpy(ch,am);
  58. t=1;
  59. break;
  60. case 2:
  61. strcpy(ch,pm);;
  62. t=0;
  63. break;
  64. default:
  65. goto aaa;
  66. }
  67. abc:
  68. sleep(1000);
  69. system("cls");
  70. printf("%02d:%02d:%02d %s",hour,min,sec,ch); // 04:35:09 AM output program
  71. sec++;
  72. if(sec==60)
  73. {
  74. sec=0;
  75. min++;
  76. }
  77. if(min==60)
  78. {
  79. min=0;
  80. g=hour;
  81. hour++;
  82. if(hour>=12&&min==0&&sec==0)
  83. {
  84. if((g-1)==11)
  85. hour=1;
  86. if(t==1)
  87. {
  88. strcpy(ch,pm);
  89. t=1;
  90. }
  91. else
  92. {
  93. strcpy(ch,am);
  94. t=0;
  95. }
  96. }
  97. }
  98. goto abc;
  99. }
  100. void hour24()
  101. {
  102. long i;
  103. int sec=0,min=0,hour=0,t,g;
  104. printf("enter hour\n");
  105. scanf("%d",&hour);
  106. if(24<hour)
  107. hour=1;
  108. printf("enter min\n");
  109. scanf("%d",&min);
  110. if(61<min)
  111. min=0;
  112. printf("enter sec\n");
  113. scanf("%d",&sec);
  114. if(61<sec)
  115. sec=0;
  116. abc:
  117. sleep(1000);
  118. system("cls");
  119. printf("%02d:%02d:%02d",hour,min,sec); // 04:35:09 output program
  120. sec++;
  121. g=hour;
  122. if(sec==60)
  123. {
  124. sec=0;
  125. min++;
  126. }
  127. if(min==60)
  128. {
  129. min=0;
  130. hour++;
  131. if(hour>=24&&min==0&&sec==0)
  132. {
  133. if((g-1)==23)
  134. hour=1;
  135. }
  136. }
  137. goto abc;
  138. }

comments powered by Disqus