#include< stdio.h>
struct time_struct
{
int hr,min,se;
};
struct time_struct add(struct time_struct t,struct time_struct t1)
{
t.se=t.se+t1.se;
if(t.se>59)
{
t.se=0;
t.min=t.min+1;
}
t.min=t.min+t1.min;
if(t.min>59)
{
t.min=0;
t.hr=t.hr+1;
}
t.hr=t.hr+t1.hr;
if(t.hr>23)
{
t.hr=0;
}
return t;
}
struct time_struct take(struct time_struct t)
{
printf("\nEnter the hour\t");
scanf("%d",&t.hr);
printf("\nEnter the minute\t");
scanf("%d",&t.min);
printf("\nEnter the second\t");
scanf("%d",&t.se);
return t;
}
void display(struct time_struct t)
{
printf("\nThe time is\t%d%c%d%c%d",t.hr,':',t.min,':',t.se);
}
void main()
{
struct time_struct t,t1;
clrscr();
t= take(t);
display(t);
t1= take(t1);
display(t1);
t=add(t,t1);
printf("\nFinal time is\n";
display(t);
getch();
}
No comments:
Post a Comment