Question

Let (,)j-0,n-1 be an arbitrary set of n integer-valued coordinates Hence the values of rj and y are integers In this question, we deine the bounding rectangle as follows 1. The rectangle has horizontal and vertical edges. 2. It is the smallest rectangle which encloses all the points (Fj, yi), j = 0, ,n-1. 3. Let the coordinates of the bounding rectangle be (uo, vo), (ui,vi), (u2, 2) and (us, vs) (u0,t0) = botton left corner (u1, v)bom right corner (u2, ) top right corner (U3,n) = top left corner Write a function to compute the bounding rectangle of the points (x,i), j-0,..n-1 The function signature is given below. Note that the return type is int. iat bounding.rect (iat a,nt O. t yO,t t . The return value is the area of the bounding rectangle. The formula for the area A is as follows: Submit your function code as your solution. 1. Write the function only. 2. Do not write a main program 3. Do not worry about header files (for math, etc.). Assume they are all given to you
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
int min(int x[],int n)
{
int min=99999;int i=0;
for(i=0;i<n;i++)
if(x[i]<min)
min=x[i];
return min;
}
int max(int x[],int n)
{
int max=-99999;int i=0;
for(i=0;i<n;i++)
if(x[i]>max)
max=x[i];
return max;
}
int bounding_rect(int n,int x[],int y[],int u[],int v[])
{
//compute the u,v array
  
//first cal min and max of x[],y[]
int min_x=min(x,n);
int max_x=max(x,n);
int min_y=min(y,n);
int max_y=max(y,n);
  
//u0=min_x,v0=min_y
u[0]=min_x;v[0]=min_y;
u[1]=max_x;v[1]=min_y;
  
u[2]=max_x;v[2]=max_y;
u[3]=min_x;v[3]=max_y;
  
return (u[2]-u[0])*(v[2]-v[0]);
  
}

//test it
int main()
{
int n,x[100],y[100],u[4]={0},v[4]={0};
int i=0;
printf("enter no of coordinates:");
scanf("%d",&n);
printf("Enter the coordinates:\n\n");
for(i=0;i<n;i++)
{printf("Enter value of x%d:",i);
scanf("%d",&x[i]);
printf("Enter value of y%d:",i);
scanf("%d",&y[i]);
}
printf("Area of bounding rectangle : %d",bounding_rect(n,x,y,u,v));
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Let (,)j-0,n-1 be an arbitrary set of n integer-valued coordinates Hence the values of rj and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT