// N1N2SM.C // Author: Peter Meyer // Last mod.: 1999-05-19 #include <stdio.h> #include <math.h> #define MAX_N 1000 double sm2000 = 29.530589; double sm3000 = 29.530583; double min_sm = 29.529; double max_sm = 29.532; void main(void) { int n1, n2, j, i=0; double cm, diff_sm2000, diff_sm3000; int results[1000][3]; printf("\nAverage month = ( n1*29 + n2*30 ) / ( n1 + n2 ) days"); printf("\nSynodic month 2000 = %.6f, synodic month 3000 = %.6f",sm2000,sm3000); printf("\n\n%5s%5s%6s%6s%12s%12s%12s", "n1","n2","n1+n2","n2-n1","av. mon.","diff.2000","diff.3000"); for ( n1=1; n1<MAX_N; n1++ ) { for ( n2=n1; n2<MAX_N; n2++ ) { cm = ((double)n1*29 + n2*30)/(n1+n2); if ( cm >= min_sm && cm <= max_sm ) { // Eliminate multiples. for ( j=0; j<i; j++ ) { if ( !(n1%results[j][1]) && !(n2%results[j][2]) ) break; } if ( j == i ) { diff_sm2000 = (( cm - sm2000 ) * 100 ) / sm2000; diff_sm3000 = (( cm - sm3000 ) * 100 ) / sm3000; if ( fabs(diff_sm2000) < 0.0001 || fabs(diff_sm3000) < 0.0001 ) { printf("\n%5d%5d%6d%6d",n1,n2,n1+n2,n2-n1); printf("%12f%11f%%%11f%%",cm,diff_sm2000,diff_sm3000); results[i][1] = n1; results[i++][2] = n2; } } } } } printf("\n\n%d results obtained.\n",i); }