Skip to content

Instantly share code, notes, and snippets.

@brunoalano
Created March 11, 2012 20:06
Show Gist options
  • Save brunoalano/2017968 to your computer and use it in GitHub Desktop.
Save brunoalano/2017968 to your computer and use it in GitHub Desktop.
Farey with logic error
/*
* Sequência de Farey
*
* Esta é uma sequência onde há uma sucessão de frações irredutíveis entre 0
* e 1, onde tem um denominador menor ou igual a N em ordem crescente.
*
* A sequência tem início em 0 (zero), e tem seu término em 1.
*/
#include <stdio.h>
/**
* Farey Build
*
* This function builds the Farey Sequence based on the N
* number passed by the first and unique argument.
*
* @param n Max sequence number
*/
void fareyBuild ( int n );
/**
* Main Function
*
* Definied by C Standard, the initial function.
*/
int main ( void )
{
int numberAlloc = 0;
printf( "Por favor, digite o numero maximo da sequencia: " );
scanf( "%d", &numberAlloc );
fareyBuild ( numberAlloc );
return 0;
}
void fareyBuild ( int n )
{
for ( int a = 1; a <= n; a++ )
{
for ( int b = 1; b <= n; b++ )
{
if ( a != b )
if ( b >= a )
printf("%d / %d\n", a, b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment