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

Time

The document contains a C program that defines a structure for time and includes a function to update the time by one second. It prompts the user to enter the current time in hh:mm:ss format, updates it, and then displays the new time. The program handles the transition between seconds, minutes, and hours, including wrapping around at midnight.
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)
2 views1 page

Time

The document contains a C program that defines a structure for time and includes a function to update the time by one second. It prompts the user to enter the current time in hh:mm:ss format, updates it, and then displays the new time. The program handles the transition between seconds, minutes, and hours, including wrapping around at midnight.
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
You are on page 1/ 1

#include <stdio.

h>

struct time
{
int hour;
int minutes;
int seconds;
};

// Function to update the time by one second


struct time timeUpdate(struct time now)
{
++now.seconds;
if (now.seconds == 60)
{ // next minute
now.seconds = 0;
++now.minutes;
if (now.minutes == 60)
{ // next hour
now.minutes = 0;
++now.hour;
if (now.hour == 24)
{ // midnight
now.hour = 0;
}
}
}
return now;
}

int main(void)
{
struct time timeUpdate(struct time now);
struct time currentTime, nextTime;

printf("Enter the time (hh:mm:ss): ");


scanf("%i:%i:%i", &currentTime.hour, &currentTime.minutes,
&currentTime.seconds);

nextTime = timeUpdate(currentTime);

printf("Updated time is %.2i:%.2i:%.2i\n", nextTime.hour, nextTime.minutes,


nextTime.seconds);

return 0;
}

You might also like