Hello, in my programming class we have to create a function that will receive a time in units of seconds and must return the equivalent time in units of hours-minutes-seconds. The function must also be called from main. I have attached what I have so far if someone could help me finish it that would be great.
int convert(void);
int main()
{
int time;
time = convert();
printf("Hour:Minute:Seconds is %d\n", time);
return 0;
}
int convert(void)
{
int T1, hour, min, sec, val1, T2;
printf("Enter the total time in seconds: ");
scanf_s("%d", &T1);
hour = T1 / 3600;
val1 = ((T1)-(3600 * hour));
min = val1 / 60;
sec = ((val1)-(min * 60));
return ();
}
#include <stdio.h> void convert(int, char *); int main() { int time; char formatted_time[100]; printf("Enter the total time in seconds: "); scanf_s("%d", &time); convert(time, formatted_time); printf("Hour:Minute:Seconds is %s\n", formatted_time); return 0; } void convert(int T1, char *result) { int hour, min, sec, val1; hour = T1 / 3600; val1 = ((T1) - (3600 * hour)); min = val1 / 60; sec = ((val1) - (min * 60)); sprintf(result, "%d-%d-%d", hour, min, sec); }
Get Answers For Free
Most questions answered within 1 hours.