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

3. Name this program range.c – This program should read five command line argume

ID: 3671304 • Letter: 3

Question

3. Name this program range.c – This program should read five command line arguments, all of which are integer values, and print the range of these values. Recall that the range of a set of numbers is the largest number in the group minus the smallest number in the group. Your program can assume that any values that the user enters are valid integers and that the user always enters five integer values. Sample executions of the program are shown below

./a.out 2 4 6 8 10 range is 8 .

/a.out 55 102 -12 87 900 range is 912

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] ) {

   if( argc == 6 ) {
        int min,max,j,i;
        min = max =atoi(argv[1]);
        for(i=2;i<=5;i++)
        {
            j = atoi(argv[i]);
            if(min>j)
                min = j;
            if(max<j)
                max = j;
        }
            printf("range is %d ", max-min);
   }
   else if( argc > 6 ) {
      printf("Too many arguments supplied. ");
   }
   else {
      printf("6 argument expected. ");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote