diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/generic/c_pascal/prog |
Initial commit
Diffstat (limited to 'macros/generic/c_pascal/prog')
-rw-r--r-- | macros/generic/c_pascal/prog/fib.py | 27 | ||||
-rw-r--r-- | macros/generic/c_pascal/prog/guess.pas | 26 | ||||
-rw-r--r-- | macros/generic/c_pascal/prog/sun.c | 39 |
3 files changed, 92 insertions, 0 deletions
diff --git a/macros/generic/c_pascal/prog/fib.py b/macros/generic/c_pascal/prog/fib.py new file mode 100644 index 0000000000..3c0bc3d8a2 --- /dev/null +++ b/macros/generic/c_pascal/prog/fib.py @@ -0,0 +1,27 @@ +# Just a little test program +from sys import stderr + +class FibSeries: + """Returns all the elements of Fibonacci series up to a given number. + + Requires one parameter (the number we're going up to).""" + + + def __init__(self,number): + self.series=[1,1] + a,b=1,1 + + while b<number: + a,b=b,a+b + if b<number: self.series.append(b) + + def writeout(self): + cnt=0 + while cnt<len(self.series): + stderr.write(str(self.series[cnt])+" ") + cnt+=1 + stderr.write("\n") + +meine = FibSeries(115) +meine.writeout() + diff --git a/macros/generic/c_pascal/prog/guess.pas b/macros/generic/c_pascal/prog/guess.pas new file mode 100644 index 0000000000..d42615780f --- /dev/null +++ b/macros/generic/c_pascal/prog/guess.pas @@ -0,0 +1,26 @@ +program guess;
+
+var
+ num1, num2: integer;
+
+begin
+ randomize;
+ num2 := random(100);
+
+ repeat
+ { make user guess }
+ write('Guess my number: ');
+ readln(num1);
+
+ { check the relation }
+ if num1 = num2 then
+ writeln('Very well!');
+ if num1 < num2 then
+ writeln('Too small.');
+ if num1 > num2 then
+ writeln('Too big.');
+ until num1 = num2;
+
+ { pause }
+ readln;
+end.
diff --git a/macros/generic/c_pascal/prog/sun.c b/macros/generic/c_pascal/prog/sun.c new file mode 100644 index 0000000000..dc9bbf184b --- /dev/null +++ b/macros/generic/c_pascal/prog/sun.c @@ -0,0 +1,39 @@ +#include <stdio.h>
+#include <math.h>
+
+int months[]={0, 31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31};
+char weekdays[7][15]={"Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"};
+
+/* this program calculates the latidude
+ where polar day begins/ends */
+void main()
+{
+ int day=24, month=6, weekday=2;
+ double angle=0;
+ double latitude;
+
+ do
+ {
+ latitude=atan(tan((23+27.0/60)*M_PI/180)*cos(angle))*180/M_PI;
+ latitude=(latitude>0)? 90-latitude : -90-latitude;
+ printf("%2d.%02d %12s : %d %02d'\n", day, month,
+ weekdays[weekday], (int)latitude,
+ (int)fabs((latitude-(int)latitude)*60));
+ if (weekday==0)
+ printf("\n");
+
+ angle+=2*M_PI/365;
+ day++;
+ if (day>months[month])
+ {
+ day=1;
+ month++;
+ if (month>12)
+ month=1;
+ }
+ if (++weekday>6)
+ weekday=0;
+ } while (month!=1);
+}
|