Output "-nan"

I am using the following code-

#include <stdio.h>
using namespace std;
double fact(double a)
if(a <= (double)1)
return (double)1.00000;
return afact(a-(double)1.00000);
int perm(double a, double b)
return fact(a)/fact(a-b);
int main() {
int t;
scanf("%d", &t);
double n, q;
scanf("%f%f", &n, &q);
double sum = (double)0.00000;
double like = (double)0.00000;
for(double i = (double)1; i <= q; i = i + (double)1.00000)
sum += (n+q)
(perm(n+q, q-i));
like += (perm(n+q, q-i));
double ll = sum;
double lm = like;
double lk = ll/lm;
printf("%f", lk);

return 0;


when I run it, it gives me “-nan” as the output but it runs successfully. what have I done wrong here? Can anybody help?

Your code isn’t readable (maybe errors in copy pasting). Can you share an ideone link?

Please format your code - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve; what input is causing the error, etc.?

1 Like