Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

Q .  Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

                                                                   PROGRAM


.  #include <stdio.h>
#include <stdlib.h>

/*
 *
 */
struct time
{
    int hours,minutes,seconds;
};
int main(){
   
    struct time t1,t2,temp;
    printf("enter the times in hours,minutes,seconds");
    scanf("%d%d%d",&t1.hours,&t1.minutes,&t1.seconds);
   
    printf("enter the times in hours,minutes,seconds");
    scanf("%d%d%d",&t2.hours,&t2.minutes,&t2.seconds);
   
    temp.hours=t1.hours+t2.hours;
    temp.minutes=t1.minutes+t2.minutes;
    temp.seconds=t1.seconds+t2.seconds;
   
    printf("\n time hours=%d \n time minutes=%d \n time seconds=%d \n",temp.hours,temp.minutes,temp.seconds);
    printf("%d: %d : %d",temp.hours,temp.minutes,temp.seconds);
}




OUTPUT

  Create a structure TIME with members hours, minutes and seconds. Write a C program to add two time objects by passing structure variables to function and display result in H: M: S format.

Comments

Post a Comment