﻿ test driver
```/*CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C                                                                             C
C  CHECK RESULTS GIVEN BY FAREY SERIES ALGORITHM                              C
C  06/11/07 (DKC)							      C
C                                                                             C
C  This program checks the results given by the algorithm for generating the  C
C  fractions in a Farey series after two given successive fractions (the      C
C  algorithm uses repeated applications of the functions B=B modulus A and    C
C  A=A modulus B).							      C
C                                                                             C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC*/
#include <stdio.h>
#include <math.h>
void farsec(unsigned int N, unsigned int M, unsigned int *R,
unsigned int NUM, unsigned int DEN, unsigned int OLDNUM,
unsigned int OLDDEN, unsigned int *STACK);
unsigned int lagrange(unsigned int N, unsigned int *R);
void main() {
unsigned int N,R[30000],S[30000],NUM,DEN,OLDNUM,OLDDEN,MAXN;
unsigned int L,M,I,J;
unsigned int STACK[2*200];
//
// ORDER OF FAREY SERIES
//
MAXN=200;
/***************/
/* BEGIN LOOP  */
/***************/
for (N=2; N<=200; N++) {
//
// GENERATE FAREY SERIES (USING HAROS' THEOREM AND LAGRANGE'S ALGORITHM)
//
L=lagrange(N,S);
printf("order=%d, size=%d \n",N,L);
//
// GENERATE FAREY SERIES USING ALGORITHM AND COMPARE RESULTS
//
for (J=0; J<L-2; J++) {
M=J;
OLDNUM=S[2*J];
OLDDEN=S[2*J+1];
NUM=S[2*J+2];
DEN=S[2*J+3];
for (I=J; I<L; I++) {
R[2*I]=0;
R[2*I+1]=0;
}
farsec(N,M,R,NUM,DEN,OLDNUM,OLDDEN,STACK);
for (I=J; I<L; I++) {
if((R[2*I]!=S[2*I])||(R[2*I+1]!=R[2*I+1])) {
printf("error: I=%d, NUMS=%d, %d \n",I,R[2*I], S[2*I]);
printf("error: I=%d, DENS=%d, %d \n",I,R[2*I+1], S[2*I+1]);
goto L400;
}
}
}
}
/***************/
/* END LOOP    */
/***************/
L400: return;
}
```