C Program to Add Times

C Program to Add Times

Write C code to add two different times in HH:MM:SS format

//Write a c program to add 2 different time

#include <stdio.h>

int main()
{
	int hour, minute, second;
	int hour1, minute1, second1;
	int hour2, minute2, second2;

	printf("Enter the time-1 in HH:MM:SS format :--> ");
	scanf("%d : %d : %d", &hour1, &minute1, &second1);

	printf("Enter the time-2 in HH:MM:SS format :--> ");
	scanf("%d : %d : %d", &hour2, &minute2, &second2);

     second = second1 + second2;
     minute = minute1 + minute2 + (second/60);
     hour = hour1 + hour2 + (minute/60);
     minute = minute % 60;
     second = second % 60;

	printf("HOUR:MINUTE:SECOND :--> %d : %d : %d", hour, minute, second);

	return 0;
}

Output:

Enter the time-1 in HH:MM:SS format :--> 5:54:56
Enter the time-2 in HH:MM:SS format :--> 4:23:19

HOUR:MINUTE:SECOND :--> 10 : 18 : 15