I want to calculate the threshold values for each round of LEACH algorithm. I am writing a program in c. The threshold depends on round # and average probability only. The function that I created has a problem calculating the result. I think there is a problem with double values. I always get 0.000 as a result!
My code is this: Expected result for initial input values of 10 0.333 and 10 should be 0.33, 0.5, 1 , 0.33 , 0.5 ,1
Note: Code was updated after some comments. Also what the code has to do is shown in the picture. Still i am getting some strange values after running it for sample input data 10 0.33 10.
void calc_threshold(double round,double avg_p)
{
double temp0=(1.0/avg_p);
double temp1=fmod(round,temp0);
double temp2= avg_p*temp1;
double temp3= 1- temp2;
double threshold = avg_p / temp3;
printf("%f\n",temp1);
int main(void)
{
int round,nodes;
double avg_p,rounds;
printf("Please give \n 2.Expected Probability \n 3.Number of Rounds \n\n in a single line separated with space:");
scanf("%d %lf %lf",&avg_p,&rounds);
for (round=0;round<rounds;round++)
{
calc_threshold(round, avg_p);
}
}
Comments
Post a Comment