Here is my code in C.
include
long int gcd(long int a,long int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int t;
long int g;
scanf("%d",&t);
double n;
while(t--)
{
scanf("%lf",&n);
if(n==(int)n)
printf("1\n");
else
{
n = (long int)(n * 10000); //since maximum number of digits after the decimal place is 4
g = gcd(n,10000); //gcd will let me reduce the fraction into it's lowest form
printf("%ld\n",10000/g); 10000/g will be the new denominator after dividing by gcd
}
}
return 0;
}