Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE C CODE CODEBLOCKS IS PROGRAM USED!!! Write a function that takes the time as

ID: 3763039 • Letter: U

Question

USE C CODE CODEBLOCKS IS PROGRAM USED!!! Write a function that takes the time as three integer arguments (for hours, minutes, and seconds), and returns the number of seconds since the last time the clock “struck 12.” Use this function to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock. Here is a sample input/output dialog:
Enter the first time as three integers: 3 12 20

Enter the second time as three integers: 4 25 30

The difference between the times is 4390 seconds

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

int funct(int h,int m,int s)

{

    return 3600*h+60*m+s;

}

int main()

{

    int hours,minutes,seconds,hours_2,seconds_2,minutes_2;

    int diff=0;

    printf("Enter the 1) hour value(0.0-23.0) : ");

    scanf("%d",&hours);

    if(hours>23 || hours<0){

        printf("Please re-enter the hour (0.0-23.0): ");

        scanf("%d",&hours);

    }

    printf("Enter the 1) minute value(0-59): ");

    scanf("%d",&minutes);

    if(minutes>59 || hours<0)

{

        printf("Please re-enter the minute (0-59): ");

        scanf("%d",&minutes);

    }

    printf("Enter the 1) second value(0,60) : ");

    scanf("%d",&seconds);

    if(seconds>60 || seconds<0)

{

      printf("Please re-enter the second (0-59): ");

        scanf("%d",&seconds);

    }

    printf("Enter the 2) hour value(0.0-23.0) : ");

    scanf("%d",&hours_2);

    if(hours>23 || hours<0)

{

        printf("Please re-enter the hour (0.0-23.0): ");

        scanf("%d",&hours_2);

    }

    printf("Enter the 2) minute value(0-59): ");

    scanf("%d",&minutes_2);

    if(minutes>59 || hours<0)

{

        printf("Please re-enter the minute (0-59): ");

        scanf("%d",&minutes_2);

    }

    printf("Enter the 2) second value(0,60) : ");

    scanf("%d",&seconds_2);

    if(seconds>60 || seconds<0)

{

        printf("Please re-enter the second (0-59): ");

        scanf("%d",&seconds_2);

    }

    diff=funct(hours_2,minutes_2,seconds_2) -funct(hours,minutes,seconds);

    printf("The amount of time in second between two times :%d",abs(diff));

    return 0;

}