Daniel Alfianto Daniel Alfianto - 1 month ago 8
C Question

How to make function from my program?

I have made a "converting time" program, and now i want to make it as function so in main program i just input the second.

#include <stdio.h>
main()
{
int h, m, s, r;
printf("Enter second:"); scanf("%i",&s);
h=s/3600;
r=s%3600;
m=r/60;
s=r%60;
printf("%i hours ",h);
printf("%i minute ",m);
printf("%i second",s);
}


so the program will be like this :

#include <stdio.h>

function()
{
/*here is converting process*/
)
main()
{
/*input second*/
/*result*/
}

Answer
#include <stdio.h>

void Time_Convert(int time)
{
    int h,m,s,r;
    h=time/3600;
    r=time%3600;
    m=r/60;
    s=r%60;
    printf("%i hours ",h);
    printf("%i minute ",m);
    printf("%i second",s);
}


main()
{
    int s;
    printf("Enter second:"); scanf("%i",&s);
    Time_Convert(s);
}