-->

a program to add two times in the format of hrs:minutes:seconds

// a program to add two times.
// e.g.
 // 2:50:20+2:40:12=5:30:32

#include<stdio.h>
#include<conio.h>
void main()
{
int hrs1,mns1,secs1;
int hrs2,mns2,secs2;
int hrs,mns,secs;
int real_hrs,real_mns,real_secs;
printf("enter first time\n");
printf("enter first hrs\n");
scanf("%d",&hrs1);
printf("enter minutes\n");
scanf("%d",&mns1);
printf("enter seconds now\n");
scanf("%d",&secs1);
printf("------------------\n");
printf("enter second time\n");
printf("enter first hrs\n");
scanf("%d",&hrs2);
printf("enter minutes\n");
scanf("%d",&mns2);
printf("enter seconds now\n");
scanf("%d",&secs2);
secs=secs1+secs2;
if(secs<60)
   {
     real_secs=secs1+secs2;
  }
else if(secs>=60)
   {
     real_mns=secs/60;
     real_secs=secs%60;
   }
mns=mns1+mns2;
if(mns<60)
   {
     real_mns=real_mns+mns1+mns2;
  }
else if(mns>=60)
   {
     hrs=mns/60;
     real_mns=mns%60;
   }
real_hrs=hrs1+hrs2+hrs;
printf("hrs=%d\n",real_hrs);
printf("minutes=%d\n",real_mns);
printf("seconds=%d\n",real_secs);
getch();
}

No comments:

Post a Comment