PROGRAM TO ADD TWO GIVEN TIME USING CPP
#include<conio.h>
#include<iostream.h>
struct time
{
int hh;
int mm;
int ss;
};
void main()
{
struct time s1,s2,s3;
clrscr();
time add(time, time);
cout<<"enter the time(HH/MM/SS)
:"; cin>>s1.hh>>s1.mm>>s1.ss;
cout<<"enter the time(HH/MM/SS)
:"; cin>>s2.hh>>s2.mm>>s2.ss;
s3=add (s1,s2);
cout<<"The time
is"<<s3.hh<<":"<<s3.mm<<":"<<s3.ss;
getch();
}
time add (time x,time y)
{
time t4;
t4.ss= (x.ss+y.ss)%60;
t4.mm=x.mm+y.mm+(t4.ss)/60;
t4.hh=x.hh+y.hh+t4.mm/60;
t4.mm=t4.mm%60;
return t4;
}
OUTPUT:
Enter the time(HH/MM/SS/) : 12
20
50
Enter the time(HH/MM/SS/) : 5
21
54
THE TIME IS 17:41:44
No comments: