正在加载图片...
12 Chapter 1.Preliminaries long jul; int ja,jy=iyyy,jm; if (jy =-0)nrerror("julday:there is no year zero."); if (jy 0)++jy; if (mm 2){ Here is an example of a block IF-structure. jm=mm+1; else --jy; jm=mm+13; ju1=(1ong)(f1oor(365.25*jy)+f1oor(30.6001*jm)+id+1720995); if (id+31L*(mm+12L*iyyy)>=IGREG){ Test whether to change to Gregorian Cal- ja=(1nt)(0.01*jy); endar. jul+=2-ja+(int)(0.25*ja): return jul; (Astronomers number each 24-hour period,starting and ending at noon,with a unique integer,the Julian Day Number [7].Julian Day Zero was a very long time ago;a convenient reference point is that Julian Day 2440000 began at noon 之 of May 23.1968.If you know the Julian Day Number that begins at noon of a 9 given calendar date,then the day of the week of that date is obtained by adding 1 and taking the result modulo base 7:a zero answer corresponds to Sunday,I to Monday,...,6 to Saturday.) While iteration.Most languages(though not FORTRAN,incidentally)provide 2S for structures like the following C example: IENTIFIC h11e(n<1000){ n=2; 2 j+=1; It is the particular feature of this structure that the control-clause(in this case n<1000)is evaluated before each iteration.If the clause is not true,the enclosed 10.621 statements will not be executed.In particular.if this code is encountered at a time Numerica when n is greater than or equal to 1000,the statements will not even be executed once. 43106 Do-While iteration.Companion to the while iteration is a related control- (outside Recipes structure that tests its control-clause at the end of each iteration.In C,it looks 腿 like this: North oftware. do n*=2; j+=1; Jwhi1e(n<1000); In this case,the enclosed statements will be executed at least once,independent of the initial value of n. Break.In this case,you have a loop that is repeated indefinitely until some condition tested somewhere in the middle of the loop (and possibly tested in more12 Chapter 1. Preliminaries Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). long jul; int ja,jy=iyyy,jm; if (jy == 0) nrerror("julday: there is no year zero."); if (jy < 0) ++jy; if (mm > 2) { Here is an example ofa block IF-structure. jm=mm+1; } else { --jy; jm=mm+13; } jul = (long) (floor(365.25*jy)+floor(30.6001*jm)+id+1720995); if (id+31L*(mm+12L*iyyy) >= IGREG) { Test whether to change to Gregorian Cal￾ja=(int)(0.01*jy); endar. jul += 2-ja+(int) (0.25*ja); } return jul; } (Astronomers number each 24-hour period, starting and ending at noon, with a unique integer, the Julian Day Number [7]. Julian Day Zero was a very long time ago; a convenient reference point is that Julian Day 2440000 began at noon of May 23, 1968. If you know the Julian Day Number that begins at noon of a given calendar date, then the day of the week of that date is obtained by adding 1 and taking the result modulo base 7; a zero answer corresponds to Sunday, 1 to Monday, ... , 6 to Saturday.) While iteration. Most languages (though not FORTRAN, incidentally) provide for structures like the following C example: while (n < 1000) { n *= 2; j += 1; } It is the particular feature of this structure that the control-clause (in this case n < 1000) is evaluated before each iteration. If the clause is not true, the enclosed statements will not be executed. In particular, if this code is encountered at a time when n is greater than or equal to 1000, the statements will not even be executed once. Do-While iteration. Companion to the while iteration is a related control￾structure that tests its control-clause at the end of each iteration. In C, it looks like this: do { n *= 2; j += 1; } while (n < 1000); In this case, the enclosed statements will be executed at least once, independent of the initial value of n. Break. In this case, you have a loop that is repeated indefinitely until some condition tested somewhere in the middle of the loop (and possibly tested in more
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有