0% found this document useful (0 votes)
22 views1 page

Code

The C program uses time functions like time, localtime, and sleep to display a digital clock that updates every second in the format hour:minute:second.

Uploaded by

Likhil 18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Code

The C program uses time functions like time, localtime, and sleep to display a digital clock that updates every second in the format hour:minute:second.

Uploaded by

Likhil 18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<stdio.

h>
#include<time.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
time_t t=time(NULL);
struct tm tm=*localtime(&t);
int hour=0;
int minute=39;
int second=25;
while(1)
{
system("clear");
printf("now: %d-%02d-%02d \n", tm.tm_mday , tm.tm_mon + 1, tm.tm_year+1900);
printf("%02d:%02d:%02d",hour,minute,second);
fflush(stdout);
second++;
if(second==60)
{
minute+=1;
second=0;
}
if(minute==60)
{
hour+=1;
minute=0;
}
if(hour==24)
{
hour=0;
minute=0;
second=0;
}
sleep(1);
}
return 0;
}

You might also like