Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ARINE MARINE 2100spr16lab TOOLS VIEW TECTED VIEW Be careful-files f from the Int

ID: 3671532 • Letter: A

Question

ARINE MARINE 2100spr16lab TOOLS VIEW TECTED VIEW Be careful-files f from the Internet can contain vinuses. Unless you need to edit, it's safer to stay in Protected View. Enable Editing ET2100 Spring 2016 Lab Assignment 6 The idea here is a program that uses a sentinel loop and some comparison inside the loop for some simple number processing, You are to create a program that has this interaction it uses all integer values: Enter your two numbers or 0 0 to quit:18 5 Ordered these numbers are 5 18 The median is 12. Enter your two numbers or 00 to quit:26 29 Ordered these numbers are 26 29 The median is 28. Enter your two numbers or 0 0 to quit:0 489 ördered these numbers are 0 489 The median is 245. Enter your two numbers or 0 0 to quit:65 0 Ordered these numbers are 0 65 The median is 33 Enter your two numbers or 0 0 to quit:0-47 Ordered these numbers are -47 0 The median is -22 Enter your two numbers or 0 0 to quit:0 You had 5 pairs of numbers. The overall range of your numbers was 536. Notes That if the numbers are entered with the larger number first they are "ordered" by being displayed in the reverse order . That the sentinel value is 0 0, not just one zero. . That a sentinel loop works by using a priming read and a read at the bottom. That when the median value would be normally something like 2.5, it is rounded up rather than down. (Which is what integer division naturally does.) This one is a bit tricky to figure out, and it involves something we know about 962

Explanation / Answer

#include <stdio.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)

int main(){
  
   int n1, n2;
   int mx , mn;
   mx = -9999;
   mn = 9999;
   int cnt = 0;
   do{

       printf("Enter your two numbers or 0 0 to quit: ");
       scanf("%d %d", &n1, &n2);

       int flag = (n1 == 0 && n2 == 0);
      
       if(flag)
           break;
       cnt++;
       printf("Ordered these numbers are: ");
       if(n1 > n2){
           printf("%d %d ", n2, n1);
           mx = max(mx, n1);
           mn = min(mn, n2);
       }
       else{
           printf("%d %d ", n1, n2);
           mx = max(mx, n2);
           mn = min(mn, n1);
       }

       printf("The median is: %d ", (n1+n2+1)/2);
   }while(!(n1 == 0 && n2 == 0));

   printf("You had %d pairs of numbers The overall range of numbers was: %d", cnt, mx - mn);
}