Problem Statement
Write a c program to construct a structure, which holds second,minute,hour
take these value from user and assign them.
construct a function update which increases the time by one second each time
#include<stdio.h>
typedef struct time_struct{
int hour;
int minute;
int sec;
}time;
void update(time *t1);
int main()
{
struct time_struct t1;
int y;
printf("enter hour \n");
scanf("%d",&t1.hour);
printf("enter minute \n");
scanf("%d",&t1.minute);
printf("enter second \n");
scanf("%d",&t1.sec);
printf("the given time is \n %d:%d:%d",t1.hour,t1.minute,t1.sec);
update(&t1);
printf("the updated time is \n %d:%d:%d",t1.hour,t1.minute,t1.sec);
scanf("%d",&y);
return 0;
}
void update(time *t1)
{
if(t1->sec==59)
{
t1->sec=0;
if(t1->minute==59)
{
t1->minute=00;
if(t1->hour==23)
{
t1->hour=00;
}
else
{
t1->hour=t1->hour+1;
}
}
else
{
t1->minute=t1->minute+1;
}
}
else
{
t1->sec=t1->sec+1;
}
return ;
}
Write a c program to construct a structure, which holds second,minute,hour
take these value from user and assign them.
construct a function update which increases the time by one second each time
#include<stdio.h>
typedef struct time_struct{
int hour;
int minute;
int sec;
}time;
void update(time *t1);
int main()
{
struct time_struct t1;
int y;
printf("enter hour \n");
scanf("%d",&t1.hour);
printf("enter minute \n");
scanf("%d",&t1.minute);
printf("enter second \n");
scanf("%d",&t1.sec);
printf("the given time is \n %d:%d:%d",t1.hour,t1.minute,t1.sec);
update(&t1);
printf("the updated time is \n %d:%d:%d",t1.hour,t1.minute,t1.sec);
scanf("%d",&y);
return 0;
}
void update(time *t1)
{
if(t1->sec==59)
{
t1->sec=0;
if(t1->minute==59)
{
t1->minute=00;
if(t1->hour==23)
{
t1->hour=00;
}
else
{
t1->hour=t1->hour+1;
}
}
else
{
t1->minute=t1->minute+1;
}
}
else
{
t1->sec=t1->sec+1;
}
return ;
}
No comments:
Post a Comment