i want to calulate coverage degree for a particular node having total number of nodes say n=10, in an xy coordinate having say size of x= y=500 and initial position of node is x = y= 0.5 and it should incremented by 1. Condition is that each node is capable of covering distance say d =5. i,ve tried but given below code is not working. pleaase somebody help me out.
#include<stdio. h>
#include<stdlib .h>
#include<math.h >
Struct node {
float pos_x;
float pos_y;
};
Struct node s[50];
int main()
{
float d;
float x = 0.5;
float y=.05;
float degree = 0.0;
int i, n;
printf(“enter the number of nodes”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
S[i].pos_x = random(500);
S[i].pos_y = random(500);
}
For(y=0.5 ; y<499.5; y++)
{
For(x=0.5 ;x<499.5; x++)
{
for(i=0; i<n; i++)
{
d = sqrt(pow((x-s[i].pos_x),2.0 )+ pow((y-s[i].pos_y),2.0));
if(d<5)
degree++;
}
degree = degree / 500.0;
printf(“ The average coverage is %f”,degree);
}
}
return(0);
}
#include<stdio. h>
#include<stdlib .h>
#include<math.h >
Struct node {
float pos_x;
float pos_y;
};
Struct node s[50];
int main()
{
float d;
float x = 0.5;
float y=.05;
float degree = 0.0;
int i, n;
printf(“enter the number of nodes”);
scanf(“%d”, &n);
for(i=0; i<n; i++)
{
S[i].pos_x = random(500);
S[i].pos_y = random(500);
}
For(y=0.5 ; y<499.5; y++)
{
For(x=0.5 ;x<499.5; x++)
{
for(i=0; i<n; i++)
{
d = sqrt(pow((x-s[i].pos_x),2.0 )+ pow((y-s[i].pos_y),2.0));
if(d<5)
degree++;
}
degree = degree / 500.0;
printf(“ The average coverage is %f”,degree);
}
}
return(0);
}
Comment