Arjun Shastry

Ranch Hand

Posts: 1906

1

posted 13 years ago

I have taken this from one of the competition.I have sloved this ,wanted to check in how many ways this can be done.

Write a program: Given a time,return the angles between the hands of the clock.[first is hour hand to minute ,minute to second,second to hour]

Return values should be of type 'float'.

Example

0)12:00:00

returns: 0,0,0

1)9:30:00

returns 105,180,75

Write a program: Given a time,return the angles between the hands of the clock.[first is hour hand to minute ,minute to second,second to hour]

Return values should be of type 'float'.

Example

0)12:00:00

returns: 0,0,0

1)9:30:00

returns 105,180,75

MH

HS Thomas

Ranch Hand

Posts: 3404

posted 13 years ago

you can calculate each hand's position based on the time.

the second hand is at 360 * (seconds / 60) degrees

the minute hand is at 360 * (minutes * 60 + seconds) / 3600

the hour hand... whatever

then, once you know the position of each individual hand, you can just subtract... and maybe take the absolute value....

this is just off the top of my head, so i haven't worked out all (well, any) of the details, so forgive me if anything isn't exactly right...

f

the second hand is at 360 * (seconds / 60) degrees

the minute hand is at 360 * (minutes * 60 + seconds) / 3600

the hour hand... whatever

then, once you know the position of each individual hand, you can just subtract... and maybe take the absolute value....

this is just off the top of my head, so i haven't worked out all (well, any) of the details, so forgive me if anything isn't exactly right...

f

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

It is sorta covered in the JavaRanch Style Guide. |