Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do this program in C? Part 3.2-3.9
    text
    copied!<p>Are multiple conditions, as in multiple if else statements needed for the intersection rectangles to be printed correctly?</p> <p>Step 3: Two rectangles intersect if they have an area in common Two rectangles do not overlap if they just touch (common edge, or common corner)</p> <p>Two rectangles intersect(as specified above)if, and only if,</p> <p>i) max(xmin1, xmin2) &lt; min(xmax1, xmax2) and</p> <p>ii) max(ymin1, ymin2) &lt; min(ymax1, ymax2)</p> <p>Your output is to be formatted. As shown below where a rectangle is shown as its lower left coordinates (xmin, ymin) and top right corner coordinates (xmax, ymax). Where the coordinates are coordinates in a Cartesian plane.</p> <p>Sample output: </p> <pre><code>enter two rectangles: 1 1 4 4 2 2 5 5 rectangle 1: (1,1)(4,4) rectangle 2: (2,2)(5,5) intersection rectangle: (2,2)(4,4) </code></pre> <p>and</p> <pre><code>enter two rectangles: 1 1 4 4 5 5 10 10 rectangle 1: (1,1)(4,4) rectangle 2: (5,5)(10,10) these two rectangles do not intersect </code></pre> <p>Code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int readRect (int *w, int *x, int *y, int *z){ return scanf("%d%d%d%d",w,x,y,z); } int minInt(int x1, int x2){ return x1, x2; } int maxInt(int y1, int y2){ return y1, y2; } int main (void){ int a,b,c,d,e,f,g,h; printf("&gt;&gt;enter two rectangles:\n"); readRect(&amp;a,&amp;b,&amp;c,&amp;d); readRect(&amp;e,&amp;f,&amp;g,&amp;h); printf("rectangle 1:(%d,%d)(%d,%d)\n",a,b,c,d); printf("rectangle 2:(%d,%d)(%d,%d)\n",e,f,g,h); if(maxInt(a,e) &lt; minInt(c,g) &amp;&amp; maxInt(b,f) &lt; minInt(d,g)){ printf("intersection rectangle: (%d,%d)(%d,%d)\n",?,?,?,?); } else { printf("these rectangles do not intersect\n"); } return EXIT_SUCCESS; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload