How to resolve the algorithm Averages/Mean time of day step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Mean time of day step by step in the XPL0 programming language
Table of Contents
Problem Statement
A particular activity of bats occurs at these times of the day: Using the idea that there are twenty-four hours in a day, which is analogous to there being 360 degrees in a circle, map times of day to and from angles; and using the ideas of Averages/Mean angle compute and show the average time of the nocturnal activity to an accuracy of one second of time.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Mean time of day step by step in the XPL0 programming language
Source code in the xpl0 programming language
include c:\cxpl\codes;
proc NumOut(N); \Display 2-digit N with leading zero
int N;
[if N<10 then ChOut(0, ^0);
IntOut(0, N);
];
proc TimeOut(Sec); \Display real seconds as HH:MM:SS
real Sec;
[NumOut(fix(Sec)/3600); ChOut(0, ^:);
NumOut(rem(0)/60); ChOut(0, ^:);
NumOut(rem(0));
];
func real HMS2Sec(H, M, S); \Convert hours, minutes, seconds to real seconds
int H, M, S;
return float(((H*60 + M)*60) + S);
func real MeanTime(A); \Return the mean of the given list of times
int A;
real X, Y, Sec;
int I;
def Pi = 3.14159265358979323846;
def S2R = Pi/(12.*60.*60.); \coefficient to convert seconds to radians
[X:= 0.0; Y:= 0.0;
for I:= 1 to A(0) do
[Sec:= HMS2Sec(A(I,0), A(I,1), A(I,2));
X:= X + Cos(Sec*S2R);
Y:= Y + Sin(Sec*S2R);
];
Sec:= ATan2(Y,X)/S2R;
if Sec < 0.0 then Sec:= Sec + 24.*60.*60.;
return Sec;
];
TimeOut(MeanTime([4, [23,00,17], [23,40,20], [00,12,45], [00,17,19]]))
You may also check:How to resolve the algorithm Loops/While step by step in the SAS programming language
You may also check:How to resolve the algorithm Permutations step by step in the BASIC programming language
You may also check:How to resolve the algorithm Hofstadter-Conway $10,000 sequence step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Meissel–Mertens constant step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Combinations step by step in the M2000 Interpreter programming language