View Code of Problem 56

#include<stdio.h>
void main()
{
	int a[3], b[3];
	scanf("%d:%d:%d", &a[0], &a[1], &a[2]);
	scanf("%d:%d:%d", &b[0], &b[1], &b[2]);
	
	int t1 = a[0] * 3600 + a[1] * 60 + a[2];
	int t2 = b[0] * 3600 + b[1] * 60 + b[2];
	if (t1 > t2)
	{
		int temp = t1;
		t1 = t2;
		t2 = temp;
	}
	int n = t2 - t1;
	int h = n / 3600;
	n -= h * 3600;
	int m = n / 60;
	n -= m * 60;
	printf("%d:", h);
	if (m < 10)
	{
		printf("0%d:", m);
	}
	else
	{
		printf("%d:", m);
	}
	if (n < 10)
	{
		printf("0%d", n);
	}
	else
	{
		printf("%d", n);
	}
}

Double click to view unformatted code.


Back to problem 56