I'm a new user here and I've started learning about C language just a few months ago, and I would like to ask for help in a task to solve.
I have to generate by random a set of n points in 2D cartesian coordinate sytem. Then to find an ellipse enveloping all of the points which area is the greatest.
So far I've got the steps but I have no idea how to do it.
1. Generate random n points.
2. I need to find an ellipse by;
a) finding the longest distance between two of these n points
b) calculating the half line for this segment
c) increasing points on this half line by one, as long as It doesn't give me an ellipse
3. calculate the area of this ellipse
I did step a) but I only stored these random points in an array.
Looks like this:
void main ()
srand( (unsigned) time( NULL ) );
int x_min = 0;
int x_max = 500;
int y_min = 0;
int y_max = 500;
printf("input a number of points:\n");
int i, j;
for (int i=0; i<5; ++i)
for (int j=0; j<2; ++j)
/* tab[i] = rand()/RAND_MAX + rand()%x_max;
tab[i] = rand()/RAND_MAX + rand()%x_max;*/
tab [i] = rand()*(x_max-x_min) / RAND_MAX + x_min;
tab [j] = rand()*(y_max-y_min) / RAND_MAX + y_min;
for(i=0; i<5; ++i)
for (j=0; j<2; ++j)
printf("[%d][%d] = %d \n", i, j, tab[i][j]);
And now is the part when I have no clue to solve. Please.