Monday, November 21, 2011

Question :

"Function" Problem..?
Can somebody solve this for me please...?

(a) Write a function named time () that has an integer parameter named seconds and three integer reference parameters named hours, min, and sec. The function is to convert the number of seconds passed to it from the main program into an equivalent number of hours, minutes and seconds.
(b) Write a program that inputs an integer number for seconds, calls the function, and displays the equivalent number of hours, minutes, and seconds.

Answer : 

Public Function ConvertSeconds(int seconds)
{
int forHours = seconds / 3600,

remainder = seconds % 3600,

forMinutes = remainder / 60,

forSeconds = remainder % 60;
Printf (“Hours : %d”,forHours);
Printf (“Minute : %d”, forMinutes);
Printf (“Seconds : %d”, forSeconds);
Getch();
}

Hope this helps

No comments:

Post a Comment