The a1
and b1
are integers. When you are dividing this (a1/b1)
you will get the output as zero. So internally the pow
function will take it as 2^0
which is 1
and this is the output you are getting here.
So the change you have to do is either you cast the a1
to float
or b1
to float
. Then this will work.
I will post a working code here.
#include <stdio.h>
int main ()
{
float rat;
float r = 2.0;
int a1 = 2;
int b1 = 4;
rat = pow (r, ((float)a1 / b1)); //Casting the a1 to float
printf ("%f", rat);
return 0;
}
Output 1.414214
will be printed out. Here as you can see I cast the a1
to float
. The same casting you can apply it for b1
also. This will also work.
For more info you can go Why dividing two integers doesn't get a float?
Hope it solved your problem.