No real surprise there. :smile: For FP comparisons, you normally have to check a range. My favorite quote for this situation is: Floating point computations are like moving piles of sand. Every time you move a pile, you leave a little sand behind.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
int main()
{
float fraction, they = (5/3);
long int i,j;
printf("Input The Fraction, to the 6th decimal place, if possable:\n");
printf("?");
scanf("%f", &fraction);
for(i=-10000;i<0;i++)
{
printf("i:%d\n",i);
for(j=-10000;j<-1;j++)
{
if((i/j)==fraction)
{
printf("Your fraction(%f) is %d/%d\n", fraction,i,j);
}
}
}
for(i=1;i<10000;i++)
{
printf("i:%d\n",i);
for(j=1;j<10000;j++)
{
if((i/j)==fraction)
{
printf("Your fraction(%f) is %d/%d\n", fraction,i,j);
}
}
}
printf("%f %f\n", fraction, they);
if(they==fraction)
{
printf("hi");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
int main()
{
float fraction, they = 3.0/5.0;
float i,j;
printf("Input The Fraction, to the 4th decimal place, if possable(no negatives):\n");
printf("?");
scanf("%f", &fraction);
for(i=1.0;i<10000.0;i+=1.0)
{
//printf("i:%f\n",i);
for(j=1.0;j<10000.0;j+=1.0)
{
they=(j/i);
//printf("%f\t", they);
if(they==fraction)
{
printf("Your fraction(%.4f) is %.0f/%.0f\n", fraction,j,i);
exit(0);
}
}
}
return 0;
}