What is the code for digital clock in C/C++ language?

1

1 Answers

Rick Sant Profile
Rick Sant answered
This is something you can use
  1. int sec = 0;
  2. int min = 0;
  3. int hour = 0;
  4. while(1)
  5. {
  6.   sleep(1000); //delay in milliseconds
  7.   ++sec;
  8.     if(sec == 60)
  9.     {
  10.       sec = 0;
  11.       ++min;
  12.       if(min == 60)
  13.       {
  14.           min = 0;
  15.           ++hour;
  16.           if(hour == 24)
  17.           {
  18.             hour = 0;
  19.           }
  20.       }
  21.     }
  22.   display(hour, min, sec);
  23. }

Answer Question

Anonymous