Decode School

Decode School - The School for Problem Solvers
Welcome to My Blog.
Need Assignment / Project Guidance (or) Training in Python?

Add two time

Get two time in hour and minutes and add them

Sample Input 1:

6:03 4:59

Sample Output 1:

11:02

Program or Solution

					    
							
#include<stdio.h>
struct time{
	int hour;
	int min;
};

int main()
{
	struct time t1,t2,t3;
	printf("Enter First time:");
	scanf("%d:%d",&t1.hour,&t1.min);
	printf("Enter second time:");
	scanf("%d:%d",&t2.hour,&t2.min);
	t3.hour=t1.hour+t2.hour;
	t3.min=t1.min+t2.min;
	if(t3.min>59)
	{
		t3.hour++;
		t3.min=t3.min-60;
	}
	printf("%d:%d",t3.hour,t3.min);
	return 0;
}
					    
					

Program Explanation

t1,t2 and t3 are structure variables, each occupies 8 bytes.

4 bytes for hour and 4 bytes for minutes.

Add minutes of t1 and t2 and store it in t3, then add hours of t1 and t2 and store it in t3.

if l3 minutes is greater than 59 then increment t3 time by and decrement t3 minutes by 60.