I am having trouble writing the code for the For EachNext st

I am having trouble writing the code for the For Each...Next statement for Chapter 9, Lesson A, number 9. How do I write the code for this portion?

Solution

// find_largest_smallest.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

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

   if ( argc != 12 ) /* argc should be 12 for correct execution */
{
printf(\"Invalid Input\ \");
return 0;
}

int i;

   if (strcmp(argv[1],\"-l\") == 0)
   {
       int max = atoi(argv[2]);
       for (i = 1; i < 10; ++i)
       {
           if(atoi(argv[2+i]) > max)
               max = atoi(argv[2+i]);
       }

       printf(\"The largest number is %d\ \", max);
   }
   else if(strcmp(argv[1],\"-s\") == 0)
   {
       int min = atoi(argv[2]);
       for (i = 1; i < 10; ++i)
       {
           if(atoi(argv[2+i]) < min)
               min = atoi(argv[2+i]);
       }
       printf(\"The smallest number is %d\ \", min);
   }
  
else
{
printf(\"Invalid Input\ \");
}

return 0;
}

/*
output:

./find_largest_smallest -l 1 2 3 4 5 6 7 8 9 9
The largest number is 9

./find_largest_smallest -s 1 2 3 4 5 6 7 8 9 9
The smallest number is 1

./find_largest_smallest -s 1 2 3 4 5 6 7 8 9
Invalid Input

./find_largest_smallest -p 1 2 3 4 5 6 7 8 9 9
Invalid Input

*/

I am having trouble writing the code for the For Each...Next statement for Chapter 9, Lesson A, number 9. How do I write the code for this portion?Solution// fi
I am having trouble writing the code for the For Each...Next statement for Chapter 9, Lesson A, number 9. How do I write the code for this portion?Solution// fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site